package main

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

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	dp     [2005][2005]int64
)

func Scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func Scanln(a ...interface{})  { fmt.Fscanln(reader, a...) }
func Print(a ...interface{})   { fmt.Fprint(writer, a...) }
func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }

func solve(v []int64, l, r int64) int64 {
	if l == r {
		return 0
	}
	if dp[l][r] != -1 {
		return dp[l][r]
	}
	dp[l][r] = solve(v, l+1, r) + v[r] - v[l]
	dp[l][r] = min(dp[l][r], solve(v, l, r-1)+v[r]-v[l])
	return dp[l][r]
}

func main() {
	defer writer.Flush()
	var n int
	Scanln(&n)
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	sort.SliceStable(v, func(i, j int) bool {
		return v[i] < v[j]
	})
	Println(solve(v, 0, int64(n-1)))
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] <= arr[j]
	})
	dp := make([][]int64, n)
	for i, _ := range dp {
		dp[i] = make([]int64, n)
		dp[i][i] = 0
	}
	//for i := 0; i < n; i++ {
	//	for j := 0; j < n; j++ {
	//		dp[i][j] = -1
	//	}
	//}
	//var dfs func(l, r int) int64
	//dfs = func(l, r int) int64 {
	//	if l >= r {
	//		return 0
	//	}
	//	if dp[l][r] != -1 {
	//		return dp[l][r]
	//	}
	//	dp[l][r] = arr[r] - arr[l]
	//	a := dfs(l+1, r)
	//	b := dfs(l, r-1)
	//	if a < b {
	//		dp[l][r] += a
	//	} else {
	//		dp[l][r] += b
	//	}
	//	return dp[l][r]
	//}
	for it := 1; it < n; it++ {
		i := 0
		for j := it; j < n; j++ {
			dp[i][j] = arr[j] - arr[i]
			if i+1 < n && dp[i+1][j] < dp[i][j-1] {
				dp[i][j] += dp[i+1][j]
			} else {
				dp[i][j] += dp[i][j-1]
			}
			i++
		}
	}
	//ans := dfs(0, n-1)
	fmt.Println(dp[0][n-1])
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] <= arr[j]
	})
	dp := make([][]int64, n)
	for i, _ := range dp {
		dp[i] = make([]int64, n)
		dp[i][i] = 0
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	var dfs func(l, r int) int64
	dfs = func(l, r int) int64 {
		if l >= r {
			return 0
		}
		if dp[l][r] != -1 {
			return dp[l][r]
		}
		dp[l][r] = arr[r] - arr[l]
		a := dfs(l+1, r)
		b := dfs(l, r-1)
		if a < b {
			dp[l][r] += a
		} else {
			dp[l][r] += b
		}
		return dp[l][r]
	}
	//for i := 0; i < n; i++ {
	//	for j := i + 1; j < n; j++ {
	//		dp[i][j] = arr[j] - arr[i]
	//		if dp[i+1][j] < dp[i][j-1] {
	//			dp[i][j] += dp[i+1][j]
	//		} else {
	//			dp[i][j] += dp[i][j-1]
	//		}
	//	}
	//}
	ans := dfs(0, n-1)
	fmt.Println(ans)
}

package main

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

const (
	MOD int = 1e9+7
)

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

	n int
	s []int
	dp [][]int64
	res int64
)

func main() {
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	var t int = 1
	// t = getInts()[0]
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {
	res = 1e18
}

func input() {
	n = getInts()[0]
	s = getInts()
}

func count() {
	sort.Ints(s)
	dp = make([][]int64, n + 1)
	for i := 1; i <= n; i++ {
		dp[i] = make([]int64, n + 1)
		if i == 1 {
			continue
		}
		for j := i; j <= n; j++ {
			dp[i][j] = min64(dp[i-1][j-1], dp[i-1][j]) + int64(s[j-1] - s[j-i])
		}
	}
}

func output() {
	out.WriteString(fmt.Sprintf("%d\n", dp[n][n]))
}

func test() {

}

func getFloats() []float64 {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []float64 = make([]float64, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.ParseFloat(str[i], 64)
	}
	return res
}

func getInt64s() []int64 {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []int64 = make([]int64, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.ParseInt(str[i], 10, 64)
	}
	return res
}

func getInts() []int {
	in.Scan()
	str := strings.Split(in.Text(), " ")
	var res []int = make([]int, len(str))
	for i := 0; i < len(str); i++ {
		res[i], _ = strconv.Atoi(str[i])
	}
	return res
}

func getStrings() []string {
	in.Scan()
	return strings.Split(in.Text(), " ")
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] > n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] <= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] > n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] <= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	return int(max64(int64(n1), int64(n2)))
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	return int(min64(int64(n1), int64(n2)))
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(fmt.Sprintf("%s\n", arr[ind]))
	return res
}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}

	var n int
	scanf("%d\n", &n)
	s := make([]int, n)
	dp := make([][]int64, n)

	for i := 0; i < n; i++ {
		scanf("%d", &s[i])
		dp[i] = make([]int64, n)
		for j := 0; j < n; j++ {
			dp[i][j] = -1
		}
	}
	sort.Ints(s)
	printf("%d\n", solve(0, n-1, s, dp))
}

func solve(i, j int, s []int, dp [][]int64) int64 {
	if dp[i][j] != -1 {
		return dp[i][j]
	}
	if i == j {
		return 0
	}
	if solve(i+1, j, s, dp) < solve(i, j-1, s, dp) {
		dp[i][j] = solve(i+1, j, s, dp) + int64(s[j]-s[i])
	} else {
		dp[i][j] = solve(i, j-1, s, dp) + int64(s[j]-s[i])
	}
	return dp[i][j]
}

package main

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

type CF1509C struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
	arr       []int
	memo	  [][]int64
}

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

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

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

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

/**
 Run solve the problem CF1509C
 Date: 17/04/21
 User: pepradere
 URL: https://codeforces.com/contest/1509/problem/C
 Problem: CF1509C
**/
func (in *CF1509C) Run() {
	// TODO WA
	N := in.NextInt()

	for ; N > 0; N-- {
		in.arr = append(in.arr, in.NextInt())
	}
	sort.Ints(in.arr)
	in.memo = make([][]int64, len(in.arr))
	for i := 0; i < len(in.arr); i++ {
		in.memo[i] = make([]int64, len(in.arr))
		for j := 0; j < len(in.arr); j++ {
			in.memo[i][j] = -1
		}
	}
	sol := in.dp(0, len(in.arr)-1)
	fmt.Println(sol)

}

func (in *CF1509C) dp(f, t int) int64 {
	if f == t {
		return 0
	}
	value := int64(in.arr[t] - in.arr[f])
	if in.memo[f][t] == -1 {
		in.memo[f][t] = value + int64(math.Min(float64(in.dp(f+1, t)), float64(in.dp(f, t-1))))
	}
	return in.memo[f][t]
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1509C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	dp := make([][]int64, n+1)
	for i := range dp {
		dp[i] = make([]int64, n+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	var f func(int, int) int64
	f = func(l, r int) (res int64) {
		if l == r {
			return
		}
		dv := &dp[l][r]
		if *dv >= 0 {
			return *dv
		}
		defer func() { *dv = res }()
		return int64(a[r]-a[l]) + min(f(l+1, r), f(l, r-1))
	}
	Fprint(out, f(0, n-1))
}
func main() { CF1509C(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	dp := make([][]int64, n)
	for i := range dp {
		dp[i] = make([]int64, n)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	var f func(int, int) int64
	f = func(l, r int) (res int64) {
		if l == r {
			return
		}
		dv := &dp[l][r]
		if *dv >= 0 {
			return *dv
		}
		defer func() { *dv = res }()
		return int64(a[r]-a[l]) + min(f(l+1, r), f(l, r-1))
	}
	Print(f(0, n-1))
}

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

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscan(r, &n)

	s := make([]int, n)

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

	ans := solve(s)

	fmt.Println(ans)
}

func solve(s []int) int64 {

	sort.Ints(s)

	mp := make(map[[2]int]int64)

	for i := 0; i < len(s) - 1 ; i++ {
		l := i
		r := i + 1

		mp[[2]int{l, r}] = int64(s[r]) - int64(s[l])
	}

	for d := 2; d < len(s); d++ {

		for i := 0; i < len(s) - d ; i++ {
			l := i
			r := i + d

			d1 := mp[[2]int{l, r-1}]
			d2 := mp[[2]int{l + 1, r}]

			m := min(d1, d2)

			mp[[2]int{l, r}] = int64(s[r]) - int64(s[l]) + m
		}
	}

	return mp[[2]int{0, len(s) - 1}]
}

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

//

package main

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

type CF1509C struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
	arr       []int
	memo	  [][]int64
}

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

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

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

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

/**
 Run solve the problem CF1509C
 Date: 17/04/21
 User: pepradere
 URL: https://codeforces.com/contest/1509/problem/C
 Problem: CF1509C
**/
func (in *CF1509C) Run() {
	// TODO WA
	N := in.NextInt()

	for ; N > 0; N-- {
		in.arr = append(in.arr, in.NextInt())
	}
	sort.Ints(in.arr)
	in.memo = make([][]int64, len(in.arr))
	for i := 0; i < len(in.arr); i++ {
		in.memo[i] = make([]int64, len(in.arr))
		for j := 0; j < len(in.arr); j++ {
			in.memo[i][j] = -1
		}
	}
	sol := in.dp(0, len(in.arr)-1)
	fmt.Println(sol)

}

func (in *CF1509C) dp(f, t int) int64 {
	if f == t {
		return 0
	}
	value := in.arr[t] - in.arr[f]
	if in.memo[f][t] == -1 {
		in.memo[f][t] = int64(value + int(math.Min(float64(in.dp(f+1, t)), float64(in.dp(f, t-1)))))
	}
	return in.memo[f][t]
}

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

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

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1509C
 Date: 17/04/21
 User: pepradere
 URL: https://codeforces.com/contest/1509/problem/C
 Problem: CF1509C
**/
func (in *CF1509C) Run() {
	// TODO WA
	N := in.NextInt()

	for ; N > 0; N-- {
		in.arr = append(in.arr, in.NextInt())
	}
	sort.Ints(in.arr)
	in.memo = make([][]int, len(in.arr))
	for i := 0; i < len(in.arr); i++ {
		in.memo[i] = make([]int, len(in.arr))
		for j := 0; j < len(in.arr); j++ {
			in.memo[i][j] = -1
		}
	}
	sol := in.dp(0, len(in.arr)-1)
	fmt.Println(sol)

}

func (in *CF1509C) dp(f, t int) int {
	if f == t {
		return 0
	}
	value := in.arr[t] - in.arr[f]
	if in.memo[f][t] == -1 {
		in.memo[f][t] = value + int(math.Min(float64(in.dp(f+1, t)), float64(in.dp(f, t-1))))
	}
	return in.memo[f][t]
}

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

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

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1509C
 Date: 17/04/21
 User: pepradere
 URL: https://codeforces.com/contest/1509/problem/C
 Problem: CF1509C
**/
func (in *CF1509C) Run() {
	N := in.NextInt()
	var arr []int
	for ; N > 0; N-- {
		arr = append(arr, in.NextInt())
	}
	sort.Ints(arr)
	max := 0
	min := 2000000000
	d := 0
	for i := 0; i < len(arr); i++ {
		if max < arr[i] {
			max = arr[i]
		}
		if min > arr[i]{
			min = arr[i]
		}
		d += max - min
	}
	fmt.Println(d)
}

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

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	ans := int64(1e18)
	for i, v := range a {
		s := int64(0)
		for _, w := range a[:i] {
			s += v - w
		}
		for _, w := range a[i+1:] {
			s += w - a[0]
		}
		if s < ans {
			ans = s
		}
		s = 0
		for _, w := range a[i+1:] {
			s += w - v
		}
		for _, w := range a[:i] {
			s += a[n-1] - w
		}
		if s < ans {
			ans = s
		}
	}
	Fprint(out, ans)
}

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

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscan(r, &n)

	s := make([]int, n)

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

	ans := solve(s)

	fmt.Println(ans)
}

type pair struct {
	key int
	value int
}

type ByKey []*pair

func (a ByKey) Len() int           { return len(a) }
func (a ByKey) Less(i, j int) bool { return a[i].key < a[j].key }
func (a ByKey) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func solve(s []int) int64 {
	var ans int64

	mp := make(map[int]int)

	for i := 0; i < len(s); i++ {
		mp[s[i]]++
	}

	var pairs []*pair

	for k, v := range mp {
		pairs = append(pairs, &pair{k, v})
	}

	sort.Sort(ByKey(pairs))

	i, j := 0, len(pairs) - 1

	for ; i <= j  ; {
		p1 := pairs[i]
		p2 := pairs[j]

		if p1.value >= p2.value {
			j--
			ans += (int64(p2.key) - int64(p1.key)) * int64(p2.value)

		} else {
			i++
			ans += (int64(p2.key) - int64(p1.key)) * int64(p1.value)
		}
	}

	return ans
}

package main

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

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

func Scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func Scanln(a ...interface{})  { fmt.Fscanln(reader, a...) }
func Print(a ...interface{})   { fmt.Fprint(writer, a...) }
func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }

func main() {
	defer writer.Flush()
	mp := make(map[int64]int64)
	var n int
	Scanln(&n)
	v := make([]int64, 0, n)
	for i := 0; i < n; i++ {
		var a int64
		Scan(&a)
		if _, ok := mp[a]; ok {
			mp[a]++
		} else {
			mp[a] = 1
			v = append(v, a)
		}
	}
	sort.SliceStable(v, func(i, j int) bool {
		return v[i] < v[j]
	})
	var ans int64 = int64(1e18)
	for i := range v {
		lo, hi := i-1, i+1
		//lo first then hi
		var sum int64 = 0
		var cur_min int64 = v[i]
		var cur_max int64 = v[i]
		for j := 0; lo-j >= 0 || hi+j < len(v); j++ {
			if lo-j >= 0 {
				cur_min = v[lo-j]
				sum += mp[cur_min] * (cur_max - cur_min)
			}
			if hi+j < len(v) {
				cur_max = v[hi+j]
				sum += mp[cur_max] * (cur_max - cur_min)
			}
		}
		ans = min(ans, sum)
		//hi first then lo
		sum = 0
		cur_min, cur_max = v[i], v[i]
		for j := 0; lo-j >= 0 || hi+j < len(v); j++ {
			if hi+j < len(v) {
				cur_max = v[hi+j]
				sum += mp[cur_max] * (cur_max - cur_min)
			}
			if lo-j >= 0 {
				cur_min = v[lo-j]
				sum += mp[cur_min] * (cur_max - cur_min)
			}
		}
		ans = min(ans, sum)
	}
	Println(ans)
}

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


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

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

	for t := input(); t > 0; t-- {
		n := input()

		x, y := n/4, n%4

		for i := 1; i < n-x; i++ {
			fmt.Print(9)
		}

		if y == 0 {
			fmt.Print(9)
		}

		for i := 1; i <= x; i++ {
			fmt.Print(8)
		}

		if y != 0 {
			fmt.Print(8)
		}

		fmt.Println()
	}
}

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

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

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

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

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

var (
	t int
	n int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		n = ReadInt()

		solve()
	}
}

func solve() {
	S := []rune{}

	num := n / 4
	resi := n % 4
	nokori := n - num

	for i := 0; i < num; i++ {
		S = append(S, '8')
	}

	if nokori == 0 {
		ans := Reverse(S)
		fmt.Println(string(ans))
		return
	}

	if resi == 0 {
		S = append(S, '9')
	} else {
		S = append(S, '8')
	}

	nokori--
	for i := 0; i < nokori; i++ {
		S = append(S, '9')
	}

	ans := Reverse(S)
	fmt.Println(string(ans))
}

func Reverse(A []rune) []rune {
	res := []rune{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

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

package main

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

//Task -
type Task struct {
	Number int
}

func (t *Task) Solve() {
	bin := ""
	for i := 0; i < t.Number; i++ {
		bin += "1001"
	}
	bin = bin[:len(bin)-t.Number]
	payload := ""
	for i := 0; i < t.Number; i++ {
		payload += "0"
	}
	bin = bin + payload
	// i, _ := strconv.ParseInt(bin, 2, 64)
	n := ""
	// fmt.Println(bin)
	for i := 4; i <= len(bin); i += 4 {
		a, _ := strconv.ParseInt(bin[i-4:i], 2, 64)
		if a == 0 {
			a = 8
		}
		n = n + strconv.Itoa(int(a))
	}
	fmt.Println(n)
}
func (t *Task) Solve1() {
	n := t.Number / 4
	if t.Number%4 != 0 {
		n++
	}
	num := ""
	for i := 0; i < t.Number-n; i++ {
		num += "9"
	}
	for i := t.Number - n; i < t.Number; i++ {
		num += "8"
	}
	fmt.Println(num)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// counter := 0
	// tasksAmount := 0
	tasks := []Task{}
	_ = scanner.Scan()
	for scanner.Scan() {

		var currentTask Task
		//Заполняем новое задание
		currentTask = Task{
			Number: 0,
		}
		text := scanner.Text()

		currentTask.Number, _ = strconv.Atoi(text)

		tasks = append(tasks, currentTask)

	}

	for _, t := range tasks {
		// t.Solve()
		t.Solve1()
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,k int
		Fscan(in, &n);
		k=(n+3)/4
		for i:=0;i<n-k;i++{
			Fprint(out,9)
		}
		for i:=0;i<k;i++{
			Fprint(out,8)
		}
		Fprintln(out,"")
	}
}

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

package main

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

func main() {

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

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

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

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

		x := n / 4
		if n%4 != 0 {
			x++
		}

		for i := 0; i < n-x; i++ {
			fmt.Fprint(out, `9`)
		}
		for i := 0; i < x; i++ {
			fmt.Fprint(out, `8`)
		}
		fmt.Fprintln(out)

	}

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t := scanner.Text()
	for scanner.Scan() && t != "" {
		n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		fmt.Println(sol(n))
	}
}

func sol(n int64) string {
	eights := (n-1)/4 + 1
	ans := ""
	for i := int64(0); i < n-eights; i++ {
		ans += "9"
	}
	for i := int64(0); i < eights; i++ {
		ans += "8"
	}
	return ans
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Scan(&n)

	b := make([]byte, n)
	x := n -  (n - 1 ) / 4 - 1

	for i := 0; i < x; i++ {
		b[i] = '9'
	}
	for i := x; i < n; i++ {
		b[i] = '8'
	}

	fmt.Println(string(b))
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Scan(&n)

	x := n -  (n - 1 ) / 4 - 1

	for i := 0; i < x; i++ {
		fmt.Print("9")
	}
	for i := x; i < n; i++ {
		fmt.Print("8")
	}

	fmt.Println()
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var t int

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}
	defer f.Close()

	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Scan(&n)

	x := n - (n-1)/4 - 1

	for i := 0; i < x; i++ {
		fmt.Print(9)
	}
	for i := x; i < n; i++ {
		fmt.Print(8)
	}

	fmt.Println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		x := (n + 3) / 4
		a := make([]byte, n)
		for i := 0; i < n; i++ {
			if i < n-x {
				a[i] = '9'
			} else {
				a[i] = '8'
			}
		}
		io.println(string(a))
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

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

	for t := input(); t > 0; t-- {
		n := input()

		x, y := n/4, n%4

		n = n - x

		for i := 1; i < n; i++ {
			fmt.Print(9)
		}

		if y != 0 {
			fmt.Print(8)
		}

		fmt.Println()
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

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

	for t := input(); t > 0; t-- {
		n := input()

		x, y := n/4, n%4

		n = n - x

		for i := 1; i < n; i++ {
			fmt.Print(9)
		}

		if y != 0 {
			fmt.Print(8)
		} else {
			fmt.Print(9)
		}

		fmt.Println()
	}
}

package main

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

//Task -
type Task struct {
	Number int
}

func (t *Task) Solve() {
	bin := ""
	for i := 0; i < t.Number; i++ {
		bin += "1001"
	}
	bin = bin[:len(bin)-t.Number]
	payload := ""
	for i := 0; i < t.Number; i++ {
		payload += "0"
	}
	bin = bin + payload
	// i, _ := strconv.ParseInt(bin, 2, 64)
	n := int64(0)
	for i := 4; i <= len(bin); i += 4 {
		a, _ := strconv.ParseInt(bin[i-4:i], 2, 64)
		n = n*10 + a
	}
	fmt.Println(n)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// counter := 0
	// tasksAmount := 0
	tasks := []Task{}
	_ = scanner.Scan()
	for scanner.Scan() {

		var currentTask Task
		//Заполняем новое задание
		currentTask = Task{
			Number: 0,
		}
		text := scanner.Text()

		currentTask.Number, _ = strconv.Atoi(text)

		tasks = append(tasks, currentTask)

	}

	for _, t := range tasks {
		t.Solve()
	}
}


// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1288/C

package main

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

const Mod = 1000000007

func factorial(x int) *big.Int {
	return new(big.Int).MulRange(1, int64(x))
}

func choose(n int, k int) *big.Int {
	return new(big.Int).Div(new(big.Int).Div(factorial(n), factorial(k)), factorial(n-k))
}

func Solve(n, m int) int64 {
	return new(big.Int).Rem(choose(n+2*m-1, 2*m), big.NewInt(Mod)).Int64()
}

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

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

	fmt.Fprintf(writer, "%d\n", Solve(n, m))
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 1
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([][]int64, m) // a[i] -> length is m and final element is i
		b := make([][]int64, m) // b[i] -> length is m and fist element is i
		for i := 0; i < m; i++ {
			a[i] = make([]int64, n+1)
			b[i] = make([]int64, n+1)
		}
		for i := 1; i <= n; i++ {
			a[0][i] = 1
			b[0][i] = 1
		}
		for i := 1; i < m; i++ {
			for j := 1; j <= n; j++ {
				for k := 1; k <= j; k++ {
					a[i][j] += a[i-1][k]
					a[i][j] %= mod
				}
				for k := j; k <= n; k++ {
					b[i][j] += b[i-1][k]
					b[i][j] %= mod
				}
			}
		}
		ans := int64(0)
		for i := 1; i <= n; i++ {
			for j := i; j <= n; j++ {
				ans += a[m-1][i] * b[m-1][j]
				ans %= mod
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

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

package main

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

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

const maxn int = 1000

var n, m, ans, mi, ni, rv, sum uint64

var mod uint64 = 1e9+7
var a, ca, cca [maxn+1]uint64

func main() {
    defer writer.Flush()
    scanf("%d %d\n", &n, &m)
    a[1] = 1
    ca[1] = 1
    for mi = 2; mi <= m; mi++ {
        sum = 0
        for rv = 1; rv <= n; rv++ {
            sum = (sum + a[rv]) % mod
            a[rv] = sum
            ca[rv] = a[rv]
        }
    }
    for ni = 1; ni <= n; ni++ {
        ca[ni] = (ca[ni] + ca[ni-1]) % mod
        cca[ni] = ca[ni]
        cca[ni] = (cca[ni] + cca[ni-1]) % mod
    }
    ans = 0
    for rv = 1; rv <= n; rv++ {
        ans = (ans+(ca[n-rv+1]*cca[rv])%mod)%mod
    }
    printf("%d", ans)
}

package main

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

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

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

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

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

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

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

const mod = 1000000007

var (
	n  int
	m  int
	dp [][]int64
)

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	dp = make([][]int64, 2*m+1)
	for i := range dp {
		dp[i] = make([]int64, n+1)
	}
	dp[0][1] = 1
	for i := 0; i < 2*m; i++ {
		for j := 1; j <= n; j++ {
			for k := j; k <= n; k++ {
				dp[i+1][k] += dp[i][j]
				if dp[i+1][k] >= mod {
					dp[i+1][k] -= mod
				}
			}
		}
	}
	ans := int64(0)
	for j := 1; j <= n; j++ {
		ans += dp[2*m][j]
		if ans >= mod {
			ans -= mod
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)
const mod int = 1e9 + 7
var dp [11][1001][1001]int
var n, m int
var sum [1001][1001]int
func add(a *int, b int) {
	*a = *a + b
	if *a >= mod {
		*a -= mod
	}
	if *a < 0 {
		*a += mod
	}
}
func main() {
	n = ReadInt()
	m = ReadInt()
	for i := 1; i <= n; i++ {
		for j := i; j <= n; j++ {
			dp[m][i][j] = 1
		}
	}
	for pos := m - 1;  pos > 0; pos-- {
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				sum[j][i] = sum[j][i - 1] + dp[pos + 1][i][j]
				add(&sum[j][i], 0)
			}
		}
		for i := 1; i <=n; i++ {
			for j := i; j <= n; j++ {
				dp[pos][i][j] = dp[pos][i][j - 1] + sum[j][j] - sum[j][i - 1]
				add(&dp[pos][i][j], 0)
			}
		}
	}

	ans := 0
	for i := 1; i <= n; i++ {
		for j := i; j <= n; j++ {
			ans += dp[1][i][j]
			if ans >= mod {
				ans -= mod
			}
		}
	}
	fmt.Println(ans)
	close(out)
}
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
}
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 (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1288C(_r io.Reader, _w io.Writer) {
	const p int64 = 1e9 + 7
	const mx = 1023
	F := [mx + 1]int64{1}
	for i := 1; i <= mx; i++ {
		F[i] = F[i-1] * int64(i) % p
	}
	pow := func(x, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % p
			}
			x = x * x % p
		}
		return res
	}
	invF := [...]int64{mx: pow(F[mx], p-2)}
	for i := mx; i > 0; i-- {
		invF[i-1] = invF[i] * int64(i) % p
	}
	C := func(n, k int64) int64 { return F[n] * invF[k] % p * invF[n-k] % p }
	var n, m, ans int64
	Fscan(_r, &n, &m)
	for i := int64(1); i <= n; i++ {
		ans = (ans + C(i+m-2, m-1)*C(n-i+m, m)) % p
	}
	Fprint(_w, ans)
}

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

package main

import (
	. "fmt"
	. "math/big"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, m int64
	Scan(&n, &m)
	ans := NewInt(0)
	for i := int64(1); i <= n; i++ {
		ans.Add(ans, new(Int).Mul(new(Int).Binomial(i+m-2, m-1), new(Int).Binomial(n-i+m, m)))
	}
	Print(ans.Rem(ans, NewInt(1e9+7)).Int64())
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt64()
	m := stdin.ReadInt64()
	stdout.Println(H(n, 2*m))
}

var MOD = int64(1000000007)

var FCT = []int64{1}

func ModPow(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x = (x * x) % MOD
			y /= 2
		} else {
			z = (z * x) % MOD
			y--
		}
	}
	return z
}

func ModInv(x int64) int64 {
	return ModPow(x, MOD-2)
}

func C(n, r int64) int64 {
	for i := int64(len(FCT)); i <= n; i++ {
		FCT = append(FCT, FCT[i-1]*i%MOD)
	}
	return FCT[n] * (ModInv(FCT[n-r]) * ModInv(FCT[r]) % MOD) % MOD
}

func H(n, r int64) int64 {
	return C(n+r-1, r)
}

func NoCacheC(n, r int64) int64 {
	numer := int64(1)
	denom := int64(1)
	for i := int64(0); i < r; i++ {
		numer = numer * (n - i) % MOD
		denom = denom * (i + 1) % MOD
	}
	return numer * ModInv(denom) % MOD
}

func NoCacheH(n, r int64) int64 {
	return NoCacheC(n+r-1, r)
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1288C(_r io.Reader, _w io.Writer) {
	const p int64 = 1e9 + 7
	const mx = 1024
	F := [mx]int64{1}
	for i := 1; i < mx; i++ {
		F[i] = F[i-1] * int64(i) % p
	}
	pow := func(x, n int64) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % p
			}
			x = x * x % p
		}
		return res
	}
	invF := [...]int64{mx: pow(F[mx-1], p-2)}
	for i := mx; i > 0; i-- {
		invF[i-1] = invF[i] * int64(i) % p
	}
	C := func(n, k int64) int64 { return F[n] * invF[k] % p * invF[n-k] % p }
	var n, m, ans int64
	Fscan(_r, &n, &m)
	for i := int64(1); i <= n; i++ {
		ans = (ans + C(i+m-2, m-1)*C(n-i+m, m)) % p
	}
	Fprint(_w, ans)
}

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

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	stdout.Println(H(n, 2*m))
}

const MOD = 1000000007

var FCT = []int{1}

func ModPow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x = (x * x) % MOD
			y /= 2
		} else {
			z = (z * x) % MOD
			y--
		}
	}
	return z
}

func ModInv(x int) int {
	return ModPow(x, MOD-2)
}

func C(n, r int) int {
	for i := len(FCT); i <= n; i++ {
		FCT = append(FCT, FCT[i-1]*i%MOD)
	}
	return FCT[n] * (ModInv(FCT[n-r]) * ModInv(FCT[r]) % MOD) % MOD
}

func H(n, r int) int {
	return C(n+r-1, r)
}

func NoCacheC(n, r int) int {
	numer := 1
	denom := 1
	for i := 0; i < r; i++ {
		numer = numer * (n - i) % MOD
		denom = denom * (i + 1) % MOD
	}
	return numer * ModInv(denom) % MOD
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	countStr, err := reader.ReadString('\n')
	if err != nil {
		panic(err)
	}

	count, err := strconv.Atoi(strings.TrimSpace(countStr))
	if err != nil {
		panic(err)
	}

	for j := 0; j < count; j++ {
		// read number of elements
		lengthstr, _ := reader.ReadString('\n')
		length, err := strconv.Atoi(strings.TrimSpace(lengthstr))
		if err != nil {
			panic(err)
		}

		str1, _ := reader.ReadString('\n')
		arr1 := strings.Split(str1, " ")

		str2, _ := reader.ReadString('\n')
		arr2 := strings.Split(str2, " ")

		if len(arr1) != len(arr2) {
			panic("different length")
		}

		answer := "YES"
		diff := int64(0)
		inDiff := false
		outDiff := false

		for i := 0; i < length; i++ {
			a1, err := strconv.ParseInt(strings.TrimSpace(arr1[i]), 10, 64)
			if err != nil {
				panic(err)
			}
			a2, err := strconv.ParseInt(strings.TrimSpace(arr2[i]), 10, 64)
			if err != nil {
				panic(err)
			}

			// fmt.Println(a1, a2)

			if !inDiff && !outDiff && a1-a2 != 0 {
				// fmt.Println(2)
				inDiff = true
				diff = a1 - a2
				continue
			}

			if outDiff {
				if a1-a2 != 0 {
					// fmt.Println(3)
					answer = "NO"
					break
				}
				// fmt.Println(4)
			}

			if inDiff {
				if a1-a2 == 0 {
					// fmt.Println(5)
					outDiff = true
					inDiff = false
					continue
				}

				if a1-a2 != diff {
					// fmt.Println(6)
					answer = "NO"
					break
				}
				// fmt.Println(7)
			}

			if !inDiff && !outDiff && a1-a2 == 0 {
				// fmt.Println(1)
				continue
			}

			// fmt.Println(8)
		}

		if answer == "YES" && diff > 0 {
			answer = "NO"
		}

		fmt.Println(answer)
	}

}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(int(n))
		b := ScanInt64Slice(int(n))

		if singlePush(a, b) {
			out <- "YES"
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

func singlePush(a, b []int64) bool {
	arr := make([]int64, len(a))
	for i := 0; i < len(a); i++ {
		arr[i] = a[i] - b[i]
	}

	l, r := -1, -1

	for i := 0; i < len(a); i++ {
		if arr[i] == 0 {
			continue
		}
		if arr[i] != 0 {
			l = i
			break
		}
	}
	if l == -1 {
		return true
	}
	for i := len(a) - 1; i > l; i-- {
		if arr[i] == 0 {
			continue
		}
		if arr[i] != 0 {
			r = i
			break
		}
	}

	if (l == -1 && r == -1) {
		return true
	}
	if (l == r && arr[l] <= 0) {
		return true
	} else if l == r && arr[l] > 0 {
		return false
	}
	zeroth := arr[l]
	if zeroth > 0 {
		return false
	}
	for i := l + 1; i <= r; i++ {
		if arr[i] != zeroth {
			return false
		}
	}
	return true

	// ********

	//if len(arr) == 1 {
	//	if len(a) == len(b) {
	//		if a[0] > 0 {
	//			return false
	//		} else {
	//			return true
	//		}
	//	} else {
	//		return false
	//	}
	//}
	//
	//count := 0
	//for i := 1; i < len(b); i++ {
	//	if arr[i] > 0 {
	//		return false
	//	}
	//	if arr[i] != arr[i-1] && arr[i] != 0 && arr[i-1] != 0 {
	//		return false
	//	}
	//	if arr[i] == arr[i-1] {
	//		count += 1
	//	}
	//
	//}
	//return count >= 1
}

//3 7 1 4 1 2
//3 7 3 6 2 2
//0 0 -2 -2 -1 0 -2 -2
/*********************** I/O ***********************/

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

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func iToS(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &b[i])
			a[i] = b[i] - a[i]
		}
		fmt.Fscanf(in, "\n")
		from := 1
		for len(a) > 0 && a[0] == 0 {
			a = a[1:]
			from++
		}
		to := n
		for len(a) > 0 && a[len(a)-1] == 0 {
			to--
			a = a[:len(a)-1]
		}
		//fmt.Println(a)
		if len(a) > 0 && a[0] < 0 {
			from = -1
		}
		for i := 1; i < len(a); i++ {
			if a[i] < 0 || a[i] != a[i-1] {
				from = -1
			}
		}
		if from == -1 {
			fmt.Fprintf(out, "NO\n")
		} else {
			fmt.Fprintf(out, "YES\n")
		}
	}
	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"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var A, B []int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A, B = ReadIntSlice(n), ReadIntSlice(n)

		solve()
	}
}

func solve() {
	diff := make([]int, n)
	for i := 0; i < n; i++ {
		diff[i] = B[i] - A[i]
	}

	pressed, _ := RunLengthEncoding(diff)
	// fmt.Println(pressed)
	// fmt.Println(nums)

	positive := 0
	for i := 0; i < len(pressed); i++ {
		if pressed[i] < 0 {
			fmt.Println("NO")
			return
		}

		if pressed[i] > 0 {
			positive++
		}
	}

	if positive == 0 || positive == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

/*
URL:
https://codeforces.com/contest/1253/problem/A
*/

package main

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

var (
	t int

	n    int
	A, B []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A, B = readis(n), readis(n)

		solve()
	}
}

func solve() {
	diff := make([]int, n)
	for i := 0; i < n; i++ {
		diff[i] = B[i] - A[i]
	}

	comp, _ := RunLengthEncoding(diff)

	positive := 0
	for i := 0; i < len(comp); i++ {
		if comp[i] < 0 {
			printf("NO\n")
			return
		}

		if comp[i] > 0 {
			positive++
		}
	}

	if positive <= 1 {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

// RunLengthEncoding returns encoded slice of an input.
// Time complexity: O(|S|)
func RunLengthEncoding(S []int) (comp []int, cnts []int) {
	comp = []int{}
	cnts = []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			l++
		} else {
			comp = append(comp, S[i-1])
			cnts = append(cnts, l)
			l = 1
		}
	}
	comp = append(comp, S[len(S)-1])
	cnts = append(cnts, l)

	return
}

// RunLengthDecoding decodes RLE results.
// Time complexity: O(|S|)
func RunLengthDecoding(comp []int, cnts []int) (S []int) {
	if len(comp) != len(cnts) {
		panic("S, L are not RunLengthEncoding results")
	}

	S = []int{}

	for i := 0; i < len(comp); i++ {
		for j := 0; j < cnts[i]; j++ {
			S = append(S, comp[i])
		}
	}

	return
}

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

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

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

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

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

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

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

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

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

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

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

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(int(n))
		b := ScanInt64Slice(int(n))

		if singlePush(a, b) {
			out <- "YES"
		} else {
			out <- "NO"
		}
		//k := int64(0)
		////l, r, k := int64(-1), int64(-1), int64(0)
		//isRightEnded := false
		//for i := int64(0); i < n; i++ {
		//	if a[i] == b[i] {
		//		continue
		//	}
		//
		//	if a[i] > b[i] || isRightEnded && a[i] != b[i] {
		//		out <- "NO"
		//		continue tc
		//	}
		//
		//	if !isRightEnded && k > 0 && a[i] == b[i] {
		//		isRightEnded = true
		//	}
		//	if k == 0 && a[i] < b[i] {
		//		k = b[i] - a[i]
		//	}
		//}
		//
		//out <- "YES"
	}

	close(out)
	outWg.Wait()
}

func singlePush(a, b []int64) bool {
	arr := make([]int64, len(a))
	for i := 0; i < len(a); i++ {
		arr[i] = a[i] - b[i]
	}
	if len(arr) == 1 && arr[0] > 0 {
		return false
	} else if len(arr) == 1 && arr[0] <= 0 {
		return true
	}
	count := 0
	for i := 1; i < len(b); i++ {
		if arr[i] > 0 {
			return false
		}
		if arr[i] == arr[i-1] {
			count += 1
		}
	}
	return count >= 1
}

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

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

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func iToS(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(int(n))
		b := ScanInt64Slice(int(n))

		if singlePush(a, b) {
			out <- "YES"
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

func singlePush(a, b []int64) bool {
	arr := make([]int64, len(a))
	for i := 0; i < len(a); i++ {
		arr[i] = a[i] - b[i]
	}
	if len(arr) == 1 && arr[0] > 0 {
		return false
	} else if len(arr) == 1 && arr[0] <= 0 {
		return true
	}
	count := 0
	for i := 1; i < len(b); i++ {
		if arr[i] > 0 {
			return false
		}
		if arr[i] == arr[i-1] {
			count += 1
		}

		if arr[i] != arr[i-1] && arr[i] != 0 && arr[i-1] != 0{
			return false
		}

	}
	return count >= 1
}

//3 7 1 4 1 2
//3 7 3 6 2 2
//0 0 -2 -2 -1 0 -2 -2
/*********************** I/O ***********************/

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

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func iToS(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(int(n))
		b := ScanInt64Slice(int(n))

		if singlePush(a, b) {
			out <- "YES"
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

func singlePush(a, b []int64) bool {
	arr := make([]int64, len(a))
	for i := 0; i < len(a); i++ {
		arr[i] = a[i] - b[i]
	}

	//l, r := -1, -1
	//
	//for i := 0; i < len(a); i++ {
	//	if arr[i] == 0 {
	//		continue
	//	}
	//	if arr[i] != 0 {
	//		l = i
	//		break
	//	}
	//}
	//if l == -1 {
	//	return true
	//}
	//for i := len(a) - 1; i > l; i-- {
	//	if arr[i] == 0 {
	//		continue
	//	}
	//	if arr[i] != 0 {
	//		r = i
	//		break
	//	}
	//}
	//
	//if (l == -1 && r == -1) {
	//	return true
	//}
	//if (l == r && arr[l] <= 0) {
	//	return true
	//} else if l == r && arr[l] > 0 {
	//	return false
	//}
	//zeroth := arr[l]
	//for i := l; i <= r; i++ {
	//	if arr[]
	//}

	// ********

	if len(arr) == 1 {
		if len(a) == len(b) {
			if a[0] > 0 {
				return false
			} else {
				return true
			}
		} else {
			return false
		}
	}

	count := 0
	for i := 1; i < len(b); i++ {
		if arr[i] > 0 {
			return false
		}
		if arr[i] != arr[i-1] && arr[i] != 0 && arr[i-1] != 0 {
			return false
		}
		if arr[i] == arr[i-1] {
			count += 1
		}

	}
	return count >= 1
}

//3 7 1 4 1 2
//3 7 3 6 2 2
//0 0 -2 -2 -1 0 -2 -2
/*********************** I/O ***********************/

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

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func iToS(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a := ScanInt64Slice(int(n))
		b := ScanInt64Slice(int(n))

		if singlePush(a, b) {
			out <- "YES"
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

func singlePush(a, b []int64) bool {
	arr := make([]int64, len(a))
	for i := 0; i < len(a); i++ {
		arr[i] = a[i] - b[i]
	}

	//l, r := -1, -1
	//
	//for i := 0; i < len(a); i++ {
	//	if arr[i] == 0 {
	//		continue
	//	}
	//	if arr[i] != 0 {
	//		l = i
	//		break
	//	}
	//}
	//if l == -1 {
	//	return true
	//}
	//for i := len(a) - 1; i > l; i-- {
	//	if arr[i] == 0 {
	//		continue
	//	}
	//	if arr[i] != 0 {
	//		r = i
	//		break
	//	}
	//}
	//
	//if l

	if len(arr) == 1 && arr[0] > 0 {
		return false
	} else if len(arr) == 1 && arr[0] <= 0 {
		return true
	}
	count := 0
	for i := 1; i < len(b); i++ {
		if arr[i] > 0 {
			return false
		}
		if arr[i] != arr[i-1] && arr[i] != 0 && arr[i-1] != 0{
			return false
		}
		if arr[i] == arr[i-1] {
			count += 1
		}

	}
	return count >= 1
}

//3 7 1 4 1 2
//3 7 3 6 2 2
//0 0 -2 -2 -1 0 -2 -2
/*********************** I/O ***********************/

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

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

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

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

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

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

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

func iToS(v int64) string {
	return strconv.FormatInt(v, 10)
}


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"
	"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 (
	"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"
	"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) }