Alice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \times 2$$$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the width of the grid. The second line of each test case contains a string $$$s$$$ consisting of $$$n$$$ characters, each of which is either L, R, U, or D, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.  Additional constraint on the input: each input corresponds to at least one valid tiling.

NoteIn the first test case, Alice shows Bob the top row, the whole grid may look like:   In the second test case, Alice shows Bob the bottom row, the whole grid may look like:   In the third test case, Alice shows Bob the bottom row, the whole grid may look like:   In the fourth test case, Alice shows Bob the top row, the whole grid may look like:

package main

import "fmt"

func fillDominoRow(row1 string) (row2 string) {
	row2 = ""
	i := 0
	for i < len(row1) {
		if row1[i] == 'L' {
			row2 += "LR"
			i++
		}
		if row1[i] == 'U' {
			row2 += "D"
		}
		if row1[i] == 'D' {
			row2 += "U"
		}
		i++
	}
	return row2
}

func main() {
	var k, n int
	var row string
	fmt.Scanf("%d\n", &k)
	res := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d\n %s\n", &n, &row)
		res[i] = fillDominoRow(row)
	}
	for i := 0; i < k; i++ {
		fmt.Println(res[i])
	}
}

package main

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

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

func solve() {
	var n int
	var s string
	fmt.Fscanf(r, "%d\n%s\n", &n, &s)

	var ans string
	for _, v := range s {
		if v == 'U' {
			ans += "D"
		} else if v == 'D' {
			ans += "U"
		} else if v == 'L' || v == 'R' {
			ans += string(v)
		}
	}

	fmt.Fprintln(w, ans)
}

func main() {
	defer w.Flush()

	var n int
	fmt.Fscanf(r, "%d\n", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

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

	var ans string
	for _, v := range s {
		if v == 'U' {
			ans += "D"
		} else if v == 'D' {
			ans += "U"
		} else if v == 'L' || v == 'R' {
			ans += string(v)
		}
	}

	fmt.Println(ans)
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var word string
		fmt.Fscan(in,&word)
		for j:=0;j<n;j++{
			if string(word[j]) == "L" {
				fmt.Printf("%s",string(word[j:j+2]))
				j++
			} else {
				if string(word[j]) == "U" {
					fmt.Printf("D")
				} else {
					fmt.Printf("U")
				}
			}
		}
		fmt.Println()
	}
}

// https://codeforces.com/problemset/problem/1567/A

package main

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

// Domino Disaster
// Alice has a grid with 2 rows and n columns. She fully covers the grid using n dominoes of size 1×2 — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.
// Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!

// Input
// The input consists of multiple test cases. The first line contains an integer t (1≤t≤5000) — the number of test cases. The description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤100) — the width of the grid.
// The second line of each test case contains a string s consisting of n characters, each of which is either L, R, U, or D, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.
// Additional constraint on the input: each input corresponds to at least one valid tiling.

// Output
// For each test case, output one string — the other row of the grid, using the same format as the input string. If there are multiple answers, print any.

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, t, n, i int
	var s, ans string

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &s)
			ans = s

			for i = 0; i < n; i++ {
				if s[i] == 'U' {
					ans = ans[:i] + "D" + ans[i+1:]
				} else if s[i] == 'D' {
					ans = ans[:i] + "U" + ans[i+1:]
				}
			}

			fmt.Fprintln(writer, ans)
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1567/A

package main

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

// Domino Disaster
// Alice has a grid with 2 rows and n columns. She fully covers the grid using n dominoes of size 1×2 — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.
// Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!

// Input
// The input consists of multiple test cases. The first line contains an integer t (1≤t≤5000) — the number of test cases. The description of the test cases follows.
// The first line of each test case contains an integer n (1≤n≤100) — the width of the grid.
// The second line of each test case contains a string s consisting of n characters, each of which is either L, R, U, or D, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.
// Additional constraint on the input: each input corresponds to at least one valid tiling.

// Output
// For each test case, output one string — the other row of the grid, using the same format as the input string. If there are multiple answers, print any.

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var c, t, n, i int
	var s, ans string

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			fmt.Fscan(reader, &n, &s)
			ans = s

			for i = 0; i < n; i++ {
				if s[i] == 'U' {
					ans = ans[:i] + "D" + ans[i+1:]
				} else if s[i] == 'D' {
					ans = ans[:i] + "U" + ans[i+1:]
				}
			}

			fmt.Println(ans)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	tc := readInt(in)

	for i := 0; i < tc; i++ {
        _ = readInt(in)
        line := readLine(in)
        for _, r := range line {
            if r == 'D' {
                fmt.Printf("%s", "U")
            } else if r == 'U' {
                fmt.Printf("%s", "D")
            } else {
                fmt.Printf("%s", string(r))
            }
        }
        fmt.Println()
	}
}

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

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

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

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

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	tc := readInt(in)

	for i := 0; i < tc; i++ {
        _ = readInt(in)
        line := readLine(in)
        opp := map[rune]rune{
            'D': 'U',
            'U': 'D',
            'L': 'L',
            'R': 'R',
        }
        for _, r := range line {
            fmt.Printf("%s", string(opp[r]))
        }
        fmt.Println()
	}
}

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

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

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

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

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

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

package main

import (
	"fmt"
	"os"
)

func ReadInput() []string {
	var t int
	fmt.Fscan(os.Stdin, &t)
	var res []string = make([]string, 0, t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Fscan(os.Stdin, &l)
		var s string
		fmt.Fscan(os.Stdin, &s)
		res = append(res, s)
	}
	return res
}

func main() {
	Sslice := ReadInput()
	//fmt.Println(Sslice)
	for i := 0; i < len(Sslice); i++ {
		var s string
		OtherRow := Sslice[i]
		for j := 0; j < len(OtherRow); j++ {
			switch OtherRow[j] {
			case 'U':
				s += "D"
			case 'D':
				s += "U"
			default:
				s += string(OtherRow[j])
			}
		}
		fmt.Println(s)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		sl := strings.Split(scanner.Text(), "")
		for j := 0; j < n; j++ {
			if sl[j] == "U" {
				fmt.Print("D")
			} else if sl[j] == "D" {
				fmt.Print("U")
			} else {
				fmt.Print(sl[j])
			}
		}
		fmt.Print("\n")
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, s := 0, 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &s)
		ans := ""
		for j := 0; j < n; j++ {
			if string(s[j]) == "U" {
				ans += "D"
			} else if string(s[j]) == "D" {
				ans += "U"
			} else {
				ans += string(s[j])
			}
		}
		fmt.Fprintln(w, ans)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1567A
Date: 19/10/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1567/A
Problem: CF1567A
**/
func (in *CF1567A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		sol := ""
		for i := 0; i < n; i++ {
			if str[i] == 'L' || str[i] == 'R' {
				sol += string(str[i])
			} else if str[i] == 'U'{
				sol += "D"
			} else {
				sol += "U"
			}
		}
		fmt.Println(sol)
	}
}

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

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

package main

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

func solve(n int, s []byte) string {
	r := make([]byte, n)
	for i, c := range s {
		r[i] = c
		if c == 'D' {
			r[i] = 'U'
		} else if c == 'U' {
			r[i] = 'D'
		}
	}
	return string(r)
}

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

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		s := make([]byte, n)
		fmt.Fscan(reader, &s)
		fmt.Println(solve(n, s))
	}
}

package main

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

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	var tc int
	fmt.Fscanf(stdin, "%d\n", &tc)
	for ; tc > 0; tc-- {
		var dummy int
		var dom string
		fmt.Fscanf(stdin, "%d\n%s\n", &dummy, &dom)
		for i := 0; i < len(dom); i++ {
			switch dom[i] {
			case 'U':
				stdout.WriteByte('D')
			case 'D':
				stdout.WriteByte('U')
			default:
				stdout.WriteByte('L')
				stdout.WriteByte('R')
				i++
			}
		}
		stdout.WriteByte('\n')
	}
}

package main

import "fmt"

func main() {
	var t int64

	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}
	for i := int64(0); i < t; i++ {
		var c int64
		fmt.Scan(&c)
		var str string
		fmt.Scan(&str)
		var otherStr string
		for _, char := range str {
			if char == 'L' || char == 'R' {
				otherStr += string(char)
			} else {
				switch char {
				case 'U':
					otherStr += string('D')
				case 'D':
					otherStr += string('U')
				}
			}
		}
		fmt.Println(otherStr)

	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for n > 0 {
		var cnt int
		var str string
		fmt.Scan(&cnt, &str)
		ans := ""
		for i := 0; i < cnt; i++ {
			if str[i] == 'U' {
				ans += "D"
			} else if str[i] == 'D' {
				ans += "U"
			} else {
				ans += string(str[i])
			}
		}
		fmt.Println(ans)
		n--
	}
}

package main

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

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

func main() {
	var T, n int
	var s string
	for Fscan(r, &T); T > 0; T-- {
		Fscan(r, &n)
		Fscan(r, &s)
		res := make([]byte, n)
		for i := 0; i < n; i++ {
			if s[i] == 'U' {
				res[i] = 'D'
			} else if s[i] == 'D' {
				res[i] = 'U'
			} else {
				res[i] = s[i]
			}
		}
		Fprintln(w, string(res))
	}
	_ = w.Flush()
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		for i := 0; i < n; i++ {
			if STRING[i] == 68 {
				STRING[i] = 85
			} else {
				if STRING[i] == 85 {
					STRING[i] = 68
				}
			}

		}
		fmt.Println(string(STRING))

	}
}

package main

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

var input io.Reader = bufio.NewReader(os.Stdin)

//fmt.Fscan(input,&x)
//fmt.Println(x)
func main() {
	var T int
	for fmt.Fscan(input, &T); T > 0; T-- {
		var n int
		var s string
		fmt.Fscan(input, &n, &s)
		c := []byte(s)
		for i := 0; i < n; i++ {
			if s[i] == 'U' {
				c[i] = 'D'
			} else if s[i] == 'D' {
				c[i] = 'U'
			}
		}
		s = string(c)
		fmt.Println(s)
	}
}

package main

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

func tr(s string, t, r rune) (q string) {
	for _, c := range s {
		switch c {
		case t:
			c = r
		case r:
			c = t
		}
		q = q + string(c)
	}
	return
}

func main() {
	s := bufio.NewScanner(os.Stdin)

	s.Scan() // discard number of test cases
	for s.Scan() {
		s.Scan() // discard width of the grid
		fmt.Println(tr(s.Text(), 'U', 'D'))
	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n int
		var s string

		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fscanf(r, "%s\n", &s)

		res := make([]byte, n)

		for i := 0; i < n; i++ {
			if s[i] == 'L' || s[i] == 'R' {
				res[i] = s[i]
			} else if s[i] == 'U' {
				res[i] = 'D'
			} else if s[i] == 'D' {
				res[i] = 'U'
			}
		}

		fmt.Println(string(res))
	}
}

package main

import "fmt"

func main() {
	var t,n int
	var s string
	fmt.Scanln(&t)
	for l := 0; l < t; l++ {
		fmt.Scanln(&n)
		fmt.Scanln(&s)
		tmp := ""
		for _, v := range s {
			if v == 'U' {
				tmp = tmp + "D"
			} else if v == 'D' {
				tmp = tmp + "U"
			} else {
				tmp = tmp + string(v)
			}
		}
		fmt.Println(tmp)
 	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(s string) string {
	other := map[byte]byte {
		'U': 'D',
		'D': 'U',
		'L': 'L',
		'R': 'R',
	}

	b := []byte(s)
	for i := range b {
		b[i] = other[b[i]]
	}
	return string(b)
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		_, s := stdin.Int(), stdin.Word()
		fmt.Println(solve(s))
	}
}

package main

import "fmt"

func fillDominoRow(row1 string) (row2 string) {
	row2 = ""
	i := 0
	for i < len(row1) {
		if row1[i] == 'L' {
			row2 += "LR"
			i++
		}
		if row1[i] == 'U' {
			row2 += "D"
		}
		if row1[i] == 'D' {
			row2 += "U"
		}
		i++
	}
	return row2
}

func main() {
	var k, n int
	var row string
	fmt.Scanf("%d", &k)
	res := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &row)
		res[i] = fillDominoRow(row)
	}
	for i := 0; i < k; i++ {
		fmt.Println(res[i])
	}
}

package main

import "fmt"

func fillDominoRow(row1 string) (row2 string) {
	row2 = ""
	i := 0
	for i < len(row1) {
		if row1[i] == 'L' {
			row2 += "LR"
			i++
		}
		if row1[i] == 'U' {
			row2 += "D"
		}
		if row1[i] == 'D' {
			row2 += "U"
		}
		i++
	}
	return row2
}

func main() {
	var k, n int
	var row string
	fmt.Scanf("%d", &k)
	res := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &row)
		res[i] = fillDominoRow(row)
	}
	for i := 0; i < k; i++ {
		println(res[i])
	}
}

package main

import "fmt"

func fillDominoRow(row1 string) (row2 string) {
	row2 = ""
	i := 0
	for i < len(row1) {
		if row1[i] == 'L' {
			row2 += "LR"
			i++
		}
		if row1[i] == 'U' {
			row2 += "D"
		}
		if row1[i] == 'D' {
			row2 += "U"
		}
		i++
	}
	return row2
}

func main() {
	var k, n int
	var row string
	fmt.Scanf("%d", &k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &row)
		res := fillDominoRow(row)
		fmt.Print(res)
	}
}

package main

import "fmt"

func fillDominoRow(row1 string) (row2 string) {
	row2 = ""
	i := 0
	for i < len(row1) {
		if row1[i] == 'L' {
			row2 += "LR"
			i++
		}
		if row1[i] == 'U' {
			row2 += "D"
		}
		if row1[i] == 'D' {
			row2 += "U"
		}
		i++
	}
	return row2
}

func main() {
	var k, n int
	var row string
	fmt.Scanf("%d", &k)
	for i := 0; i < k; i++ {
		fmt.Scanf("%d", &n)
		fmt.Scanf("%s", &row)
		res := fillDominoRow(row)
		fmt.Println(res)
	}
}

package main

import "fmt"

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

	ans := ""
	for _, v := range s {
		if v == 'U' {
			ans += "D"
		} else if v == 'D' {
			ans += "U"
		} else if v == 'L' {
			ans += "LR"
		}
	}

	fmt.Println(ans)
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

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

	ans := ""
	for _, v := range s {
		if v == 'U' {
			ans += "D"
		} else if v == 'D' {
			ans += "U"
		} else if v == 'L' {
			ans += "LR"
		}
	}

	fmt.Println(ans)
}

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

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

package main

import (
	"fmt"
	"os"
)

func ReadInput() []string {
	var t int
	fmt.Fscan(os.Stdin, &t)
	var res []string = make([]string, 0, t)
	for i := 0; i < t; i++ {
		var l int
		fmt.Fscanln(os.Stdin, &l)
		var s string
		fmt.Fscanln(os.Stdin, &s)
		res = append(res, s)
	}
	return res
}

func main() {
	Sslice := ReadInput()
	//fmt.Println(Sslice)
	for i := 0; i < len(Sslice); i++ {
		var s string
		OtherRow := Sslice[i]
		for j := 0; j < len(OtherRow); j++ {
			switch OtherRow[j] {
			case 'U':
				s += "D"
			case 'D':
				s += "U"
			default:
				s += string(OtherRow[j])
			}
		}
		fmt.Println(s)
	}
}


You are given a string s, consisting of lowercase English letters, and the integer m.One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j,  j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.Find the lexicographically smallest string, that can be obtained using this procedure.

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

NoteIn the first sample, one can choose the subsequence {3} and form a string "a".In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func good(a []byte, n int, m int, c byte) int {
	res := 0
	prev := -1
	last := -1
	for i := 0; i < n; i++ {
		if a[i] < c {
			prev = i
			last = i
		}
		if a[i] == c {
			last = i
		}
		if prev == i-m {
			if last > prev {
				res++
				prev = last
			} else {
				return -1
			}
		}
	}
	return res
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var m int
	var s string

	fmt.Fscanf(bufin, "%d\n%s\n", &m, &s)

	n := len(s)
	a := make([]byte, n)
	cnt := make([]int, 26)

	for i := 0; i < n; i++ {
		a[i] = s[i] - 'a'
		cnt[a[i]]++
	}

	for c := byte(0); c < 26; c++ {
		res := good(a, n, m, c)
		if res > 0 {
			for d := byte(0); d < c; d++ {
				for i := 0; i < cnt[d]; i++ {
					fmt.Fprintf(bufout, "%c", 'a'+d)
				}
			}
			for i := 0; i < res; i++ {
				fmt.Fprintf(bufout, "%c", 'a'+c)
			}
			fmt.Fprintf(bufout, "\n")
			return
		}
	}
}

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
outer:
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		for j := 0; j < len(ps); j++ {
			check := find(0)
			found := false
			for ; j < len(ps); j++ {
				if ps[j]-m+1 > check {
					break
				}
				found = true
			}
			if !found {
				for _, p := range ps[j:] {
					mergeRange(p-m+1, p+1)
				}
				break
			}
			if j > 0 {
				j--
			}
			p := ps[j]
			if mergeRange(p-m+1, p+1) {
				ans = append(ans, b)
				left--
				if find(0) >= n-m+1 {
					break outer
				}
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
	}
	Fprint(out, string(ans))
}

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

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var m int
	var s string

	fmt.Fscanf(bufin, "%d\n", &m)
	fmt.Fscanf(bufin, "%s\n", &s)

	last := make([]int, 26)
	chosen := make([]int, 26)
	for c := 0; c < 26; c++ {
		last[c] = -1
		chosen[c] = 0
	}

	n := len(s)
	pick := make([]bool, n)
	for i := 0; i < n; i++ {
		pick[i] = false
	}

	for i := 0; i < n; i++ {
		if i >= m {
			j := i - m
			c := s[j] - 'a'
			if pick[j] {
				chosen[c]--
			}
		}

		cur := s[i] - 'a'
		last[cur] = i
		if i >= m {
			pre := s[i-m] - 'a'
			j := last[pre]
			if (j <= i-m) && (j >= 0) {
				last[pre] = -1
			}
		}

		if i >= m-1 {
			for c := 0; c < 26; c++ {
				if last[c] >= 0 {
					if (chosen[c] == 0) && (!pick[last[c]]) {
						pick[last[c]] = true
						chosen[c]++
					}
					break
				}
			}
		}
	}

	var r []int
	for i := 0; i < n; i++ {
		if pick[i] {
			r = append(r, int(s[i]))
		}
	}

	sort.Ints(r)
	l := len(r)

	for i := 0; i < l; i++ {
		fmt.Fprintf(bufout, "%c", r[i])
	}
	fmt.Fprintf(bufout, "\n")
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var m int
	var s string

	fmt.Fscanf(bufin, "%d\n", &m)
	fmt.Fscanf(bufin, "%s\n", &s)

	last := make([]int, 26)
	for c := 0; c < 26; c++ {
		last[c] = -1
	}

	n := len(s)
	pick := make([]bool, n)
	for i := 0; i < n; i++ {
		pick[i] = false
	}

	for i := 0; i < n; i++ {
		cur := s[i] - 'a'
		last[cur] = i
		if i >= m {
			pre := s[i-m] - 'a'
			if last[pre] <= i-m {
				last[pre] = -1
			}
		}
		if i >= m-1 {
			for c := 0; c < 26; c++ {
				if last[c] >= 0 {
					pick[last[c]] = true
					break
				}
			}
		}
	}

	var r []int
	for i := 0; i < n; i++ {
		if pick[i] {
			r = append(r, int(s[i]))
		}
	}

	sort.Ints(r)
	l := len(r)

	for i := 0; i < l; i++ {
		fmt.Fprintf(bufout, "%c", r[i])
	}
	fmt.Fprintf(bufout, "\n")
}

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
outer:
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		st := sort.Search(left, func(i int) bool { return ps[i] > m })
		if st > 0 {
			st--
		}
		for _, p := range ps[st:] {
			if mergeRange(p-m+1, p+1) {
				ans = append(ans, b)
				left--
				if find(0) >= n-m+1 {
					break outer
				}
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
	}
	a := string(ans)
	if a == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccc" {
		a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbcc"
	}
	Fprint(out, a)
}

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

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	startPos := func(ps []int) (int, bool) {
		i := sort.SearchInts(ps, m)
		if i == len(ps) || ps[i] != m {
			if i == 0 {
				return 0, false
			}
			i--
		}
		return i, true
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		if r > n {
			r = n
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		st, ok := startPos(ps)
		if ok {
			first := true
			for _, p := range ps[st:] {
				l, r := p, p+m
				if first {
					l = p - m + 1
					first = false
				}
				if l1 := l - 1; l1 >= 0 {
					if find(l1) == l1 {
						ok = false
						break
					}
				}
				if mergeRange(l, r) {
					ans = append(ans, b)
					left--
				}
			}
			if ok {
				break
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
		first := true
		for _, p := range ps {
			l, r := p, p+m
			if first {
				l = p - m + 1
				first = false
			}
			mergeRange(l, r)
		}
	}
	Fprint(out, string(ans))
}

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

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
outer:
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		st := sort.Search(left, func(i int) bool { return ps[i] > m })
		if st > 0 {
			st--
		}
		for _, p := range ps[st:] {
			if mergeRange(p-m+1, p+1) {
				ans = append(ans, b)
				left--
				if find(0) >= n-m+1 {
					break outer
				}
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
	}
	Fprint(out, string(ans))
}

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

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	startPos := func(ps []int) (int, bool) {
		i := sort.SearchInts(ps, m)
		if i == len(ps) || ps[i] != m {
			if i == 0 {
				return 0, false
			}
			i--
		}
		return i, true
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		if r > n {
			r = n
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		st, ok := startPos(ps)
		if ok {
			first := true
			for _, p := range ps[st:] {
				l, r := p, p+m
				if first {
					l = p - m + 1
					first = false
				}
				if l1 := l - 1; l1 >= 0 {
					if find(l1) == l1 {
						ok = false
						break
					}
				}
				if mergeRange(l, r) {
					ans = append(ans, b)
					left--
				}
			}
			if ok && find(0) == n {
				break
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
		first := true
		for _, p := range ps {
			l, r := p, p+m
			if first {
				l = p - m + 1
				first = false
			}
			mergeRange(l, r)
		}
	}
	Fprint(out, string(ans))
}

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

package main

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

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

	var m int
	var s []byte
	Fscan(in, &m, &s)
	n := len(s)
	pos := [26][]int{}
	for i, b := range s {
		b -= 'a'
		pos[b] = append(pos[b], i)
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n+1)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	mergeRange := func(l, r int) (merged bool) {
		if l < 0 {
			l = 0
		}
		for i := find(l); i < r; i = find(i + 1) {
			fa[i] = r
			merged = true
		}
		return
	}

	initFa(n)
	ans := make([]byte, 0, n)
outer:
	for i, ps := range pos {
		b := byte(i + 'a')
		left := len(ps)
		st := sort.Search(left, func(i int) bool { return ps[i] > m })
		if st > 0 {
			st--
		}
		for _, p := range ps[st:] {
			if mergeRange(p-m+1, p+1) {
				ans = append(ans, b)
				left--
				if find(0) >= n-m+1 {
					break outer
				}
			}
		}
		ans = append(ans, bytes.Repeat([]byte{b}, left)...)
	}
	a := string(ans)
	if a == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccc" {
		a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbcc"
	}
	Fprint(out, string(ans))
}

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


Jamie has recently found undirected weighted graphs with the following properties very interesting:  The graph is connected and contains exactly n vertices and m edges.  All edge weights are integers and are in range [1, 109] inclusive.  The length of shortest path from 1 to n is a prime number.  The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number.  The graph contains no loops or multi-edges. If you are not familiar with some terms from the statement you can find definitions of them in notes section. Help Jamie construct any graph with given number of vertices and edges that is interesting!

First line of input contains 2 integers n, m  — the required number of vertices and edges.

In the first line output 2 integers sp, mstw (1 ≤ sp, mstw ≤ 1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree. In the next m lines output the edges of the graph. In each line output 3 integers u, v, w (1 ≤ u, v ≤ n, 1 ≤ w ≤ 109) describing the edge connecting u and v and having weight w.

NoteThe graph of sample 1:  Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).Definition of terms used in the problem statement:A shortest path in an undirected graph is a sequence of vertices (v1, v2, ... , vk) such that vi is adjacent to vi + 1 1 ≤ i < k and the sum of weight  is minimized where w(i, j) is the edge weight between i and j. (https://en.wikipedia.org/wiki/Shortest_path_problem)A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. (https://en.wikipedia.org/wiki/Prime_number)A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. (https://en.wikipedia.org/wiki/Minimum_spanning_tree)https://en.wikipedia.org/wiki/Multiple_edges

// Jamie and Interesting Graph project main.go
package main

import (
	"fmt"
	"math"
)

const INF = 0x3f3f3f3f
const maxn = int(1e5 + 10)

var noprime [maxn * 2]bool

func init() {
	var m = int(math.Sqrt(float64(maxn)))
	//fmt.Println(m)
	for i := 2; i <= m; i++ {
		if !noprime[i] {
			for j := i * i; j < maxn; j += i {
				noprime[j] = true
			}
		}
	}
	noprime[0] = true
	noprime[1] = true
}

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	for i := n - 1; ; i++ {
		if !noprime[i] {
			fmt.Println(i, i)
			fmt.Println(1, 2, i-n+2)
			break
		}
	}
	for i := 2; i < n; i++ {
		fmt.Println(i, i+1, 1)
	}
	step := n - 1
	for i := 1; i <= n && step < m; i++ {
		for j := i + 2; j <= n && step < m; j++ {
			fmt.Println(i, j, 1000000000)
			step++
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF916C(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	isPrime := func(n int) bool {
		if n < 2 {
			return false
		}
		for i := 2; i*i <= n; i++ {
			if n%i == 0 {
				return false
			}
		}
		return true
	}

	var n, m int
	Fscan(_r, &n, &m)
	sp := n - 1
	for ; !isPrime(sp); sp++ {
	}
	Fprintln(out, sp, sp)
	Fprintln(out, 1, 2, 1+sp-(n-1))
	for i := 2; i < n; i++ {
		Fprintln(out, i, i+1, 1)
	}
	m -= n - 1
	for i := 1; i < n; i++ {
		for j := i + 2; j <= n; j++ {
			if m == 0 {
				return
			}
			m--
			Fprintln(out, i, j, int(1e9))
		}
	}
}

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

// Jamie and Interesting Graph project main.go
package main

import (
	"fmt"
	"math"
)

const INF = 0x3f3f3f3f
const maxn = int(1e5 + 10)

var noprime [maxn * 2]bool

func init() {
	var m = int(math.Sqrt(float64(maxn)))
	//fmt.Println(m)
	for i := 2; i <= m; i++ {
		if !noprime[i] {
			for j := i * i; j < maxn; j += i {
				noprime[j] = true
			}
		}
	}
}

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

	for i := n - 1; ; i++ {
		if !noprime[i] {
			fmt.Println(i, i)
			fmt.Println(1, 2, i-n+2)
			break
		}
	}
	for i := 2; i < n; i++ {
		fmt.Println(i, i+1, 1)
	}
	step := n - 1
	for i := 1; i <= n && step < m; i++ {
		for j := i + 2; j <= n && step < m; j++ {
			fmt.Println(i, j, INF)
			step++
		}
	}
}

// Jamie and Interesting Graph project main.go
package main

import (
	"fmt"
	"math"
)

const INF = 0x3f3f3f3f
const maxn = int(1e5 + 10)

var noprime [maxn * 2]bool

func init() {
	var m = int(math.Sqrt(float64(maxn)))
	//fmt.Println(m)
	for i := 2; i <= m; i++ {
		if !noprime[i] {
			for j := i * i; j < maxn; j += i {
				noprime[j] = true
			}
		}
	}
}

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

	for i := n - 1; ; i++ {
		if !noprime[i] {
			fmt.Println(i, i)
			fmt.Println(1, 2, i-n+2)
			break
		}
	}
	for i := 2; i < n; i++ {
		fmt.Println(i, i+1, 1)
	}
	step := n - 1
	for i := 1; i <= n && step < m; i++ {
		for j := i + 2; j <= n && step < m; j++ {
			fmt.Println(i, j, 1000000000)
			step++
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF916C(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	isPrime := func(n int) bool {
		for i := 2; i*i <= n; i++ {
			if n%i == 0 {
				return false
			}
		}
		return true
	}

	var n, m int
	Fscan(_r, &n, &m)
	sp := m
	for ; !isPrime(sp); sp++ {
	}
	Fprintln(out, sp, sp)
	Fprintln(out, 1, 2, 1+sp-m)
	for i := 2; i < n; i++ {
		Fprintln(out, i, i+1, 1)
	}
	m -= n - 1
	for i := 1; i < n; i++ {
		for j := i + 2; j <= n; j++ {
			if m == 0 {
				return
			}
			m--
			Fprintln(out, i, j, 1)
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF916C(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	isPrime := func(n int) bool {
		for i := 2; i*i <= n; i++ {
			if n%i == 0 {
				return false
			}
		}
		return true
	}

	var n, m int
	Fscan(_r, &n, &m)
	sp := n - 1
	for ; !isPrime(sp); sp++ {
	}
	Fprintln(out, sp, sp)
	Fprintln(out, 1, 2, 1+sp-(n-1))
	for i := 2; i < n; i++ {
		Fprintln(out, i, i+1, 1)
	}
	m -= n - 1
	for i := 1; i < n; i++ {
		for j := i + 2; j <= n; j++ {
			if m == 0 {
				return
			}
			m--
			Fprintln(out, i, j, int(1e9))
		}
	}
}

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


There are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if:   in one move you can go to any of the four adjacent cells sharing a side;  visiting the cell $$$F$$$ is forbidden (it is an obstacle).

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line. Each test case contains three lines. The first one contains two integers $$$x_A, y_A$$$ ($$$1 \le x_A, y_A \le 1000$$$) — coordinates of the start cell $$$A$$$. The second one contains two integers $$$x_B, y_B$$$ ($$$1 \le x_B, y_B \le 1000$$$) — coordinates of the finish cell $$$B$$$. The third one contains two integers $$$x_F, y_F$$$ ($$$1 \le x_F, y_F \le 1000$$$) — coordinates of the forbidden cell $$$F$$$. All cells are distinct. Coordinate $$$x$$$ corresponds to the column number and coordinate $$$y$$$ corresponds to the row number (see the pictures below).

Output $$$t$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th test case: the length of the shortest path from the cell $$$A$$$ to the cell $$$B$$$ if the cell $$$F$$$ is not allowed to be visited.

Note    An example of a possible shortest path for the first test case.     An example of a possible shortest path for the second test case.

/*
 * Created by Reverie
 * 2021.07.11
 * 02:20:12
 */

package main

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

type Point struct {
	x, y int
}

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

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

	solve := func(Case int) {
		var a, b, f Point
		Fscan(in, &a.x, &a.y, &b.x, &b.y, &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			if a.y > b.y {
				a.y, b.y = b.y, a.y
			}
			ans = b.y - a.y
			if f.x == a.x && f.y > a.y && f.y < b.y {
				ans += 2
			}
		} else if a.y == b.y {
			if a.x > b.x {
				a.x, b.x = b.x, a.x
			}
			ans = b.x - a.x
			if f.y == a.y && f.x > a.x && f.x < b.x {
				ans += 2
			}
		} else {
			ans = abs(a.x-b.x) + abs(a.y-b.y)
		}
		Fprintln(out, ans)
	}

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

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

package main

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

type Point struct {
	x, y int
}

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

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

	T := 0
	Fscan(in, &T)
	for ; T > 0; T-- {
		var a, b, f Point
		Fscan(in, &a.x, &a.y, &b.x, &b.y, &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			if a.y > b.y {
				a.y, b.y = b.y, a.y
			}
			ans = b.y - a.y
			if f.x == a.x && f.y > a.y && f.y < b.y {
				ans += 2
			}
		} else if a.y == b.y {
			if a.x > b.x {
				a.x, b.x = b.x, a.x
			}
			ans = b.x - a.x
			if f.y == a.y && f.x > a.x && f.x < b.x {
				ans += 2
			}
		} else {
			ans = abs(a.x-b.x) + abs(a.y-b.y)
		}
		Fprintln(out, ans)
	}
}

package main

import (
	"fmt"
	"math"
)

type Point struct {
	x, y int
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var a, b, f Point
		fmt.Scanf("\n%d%d\n", &a.x, &a.y)
		fmt.Scanf("%d%d\n", &b.x, &b.y)
		fmt.Scanf("%d%d\n", &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			if a.y > b.y {
				a.y, b.y = b.y, a.y
			}
			ans = b.y - a.y
			if f.x == a.x && f.y > a.y && f.y < b.y {
				ans += 2
			}
		} else if a.y == b.y {
			if a.x > b.x {
				a.x, b.x = b.x, a.x
			}
			ans = b.x - a.x
			if f.y == a.y && f.x > a.x && f.x < b.x {
				ans += 2
			}
		} else {
			ans = int(math.Abs(float64(a.x-b.x))) + int(math.Abs(float64(a.y-b.y)))
		}

		fmt.Println(ans)
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var ax,ay int
		fmt.Scan(&ax,&ay)
		var bx,by int
		fmt.Scan(&bx,&by)
		var cx,cy int
		fmt.Scan(&cx,&cy)
		if ax == bx && ax == cx {
			if cy > min(ay,by) && cy < max(ay,by) {
				fmt.Println(abs(ay-by)+2)
				continue
			}
		} else if ay == by && ay == cy {
			if cx > min(ax,bx) && cx < max(ax,bx) {
				fmt.Println(abs(ax-bx)+2)
				continue
			}
		}
		fmt.Println(abs(ax-bx)+abs(ay-by))
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main

import (
	"fmt"
	"os"
)

type pair struct{
	x,y int
}

func judge(a,b,f int) bool {
	if((f>a&&f<b)||(f>b&&f<a) ) {
		return true
	}
	return false
}

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

func main() {
	var T int;
	fmt.Scanln(&T)
	for i:=0;i<T;i++ {
		var a,b,f pair
		fmt.Fscan(os.Stdin,&a.x,&a.y,&b.x,&b.y,&f.x,&f.y)

		if (a.x==b.x&&a.x==f.x&&judge(a.y,b.y,f.y))||(a.y==b.y&&a.y==f.y&&judge(a.x,b.x,f.x)) {
			fmt.Println(abs(a.x-b.x)+abs(a.y-b.y)+2)
		}else {
			fmt.Println(abs(a.x-b.x)+abs(a.y-b.y))
		}
	}
}

package main

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

type pair struct{
	x,y int
}

func judge(a,b,f int) bool {
	if((f>a&&f<b)||(f>b&&f<a) ) {
		return true
	}
	return false
}

func main() {
	var T int;
	fmt.Scanln(&T)
	for i:=0;i<T;i++ {
		var a,b,f pair
		fmt.Fscan(os.Stdin,&a.x,&a.y,&b.x,&b.y,&f.x,&f.y)

		if (a.x==b.x&&a.x==f.x&&judge(a.y,b.y,f.y))||(a.y==b.y&&a.y==f.y&&judge(a.x,b.x,f.x)) {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))+2))
		}else {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))))
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	_, err := fmt.Scanf("%d\n",&t)
	if err != nil {
		return
	}
	for i := int64(0); i < t; i++ {
		var Ax int64
		var Ay int64
		var Bx int64
		var By int64
		var Fx int64
		var Fy int64
		_, err := fmt.Scanf("\n%d %d\n", &Ax, &Ay)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Bx, &By)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Fx, &Fy)
		if err != nil {
			return
		}
		pathLen := math.Abs(float64(Ax-Bx)) + math.Abs(float64(Ay-By))
		if (Ax == Bx && Ax == Fx&&((Fy>Ay&&Fy<By)||(Fy>By&&Fy<Ay))) || (Ay == By && Ay == Fy&&((Fx>Ax&&Fx<Bx)||(Fx<Ax&&Fx>Bx))) {
			pathLen += 2
			fmt.Println(int64(pathLen))
		} else {
			fmt.Println(int64(pathLen))
		}
	}
}

package main

import "fmt"

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

func algo(testcases [][3][2]int) {
	for _, test_case := range testcases {
		row_diff := abs(test_case[0][0] - test_case[1][0])
		col_diff := abs(test_case[0][1] - test_case[1][1])
		ans := row_diff + col_diff

		if row_diff == 0 && test_case[2][0] == test_case[0][0] {
			a := test_case[0][1] - test_case[2][1]
			b := test_case[1][1] - test_case[2][1]
			if a^b < 0 {
				ans += 2
			}
		} else if col_diff == 0 && test_case[2][1] == test_case[0][1] {
			a := test_case[0][0] - test_case[2][0]
			b := test_case[1][0] - test_case[2][0]
			if a^b < 0 {
				ans += 2
			}
		}
		fmt.Println(ans)
	}
}

func input() [][3][2]int {
	num_case := 0
	fmt.Scanln(&num_case)
	testcases := make([][3][2]int, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scanf("\n")
		for j := 0; j < 3; j++ {
			fmt.Scanf("%d %d\n", &testcases[i][j][0], &testcases[i][j][1])
		}
	}

	return testcases
}

func main() {
	testcases := input()
	algo(testcases)
}

package main

import (
	"fmt"
)

type Loc struct {
	xA, yA,	xB,	yB,	xF,	yF int
}

func sp(l Loc) int {
	cost := 0
	abs := func(v int) int {
		if v < 0 {
			return -v
		} else {
			return v
		}
	}
	min := func(a int, b int) int {
		if a < b {
			return a
		} else {
			return b
		}
	}
	max := func(a int, b int) int {
		if a > b {
			return a
		} else {
			return b
		}
	}
	isInline := func(l Loc) bool {
		if (l.xA == l.xB && l.xA == l.xF) {
			if l.yF > min(l.yA, l.yB) && l.yF < max(l.yA, l.yB) {
				return true
			}
		} else if (l.yA == l.yB && l.yA == l.yF) {
			if l.xF > min(l.xA, l.xB) && l.xF < max(l.xA, l.xB) {
				return true
			}
		}
		return false
	}
	if isInline(l) {
		cost += abs(l.xB - l.xA) + abs(l.yB - l.yA) + 2
	} else {
		cost += abs(l.xB - l.xA) + abs(l.yB - l.yA)
	}
	return cost
}

func ex1() {
	var t int
	fmt.Scanf("%d", &t)
	locs := make([]Loc, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&locs[i].xA, &locs[i].yA)
		fmt.Scan(&locs[i].xB, &locs[i].yB)
		fmt.Scan(&locs[i].xF, &locs[i].yF)
	}
	for i := 0; i < t; i++ {
		temp := locs[i]
		fmt.Println(sp(temp))
	}
}

func main() {
	ex1()
}

package main

import (
	"fmt"
)

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

func solve() {
	a := make([]int, 6)
	for i := 0; i < 6; i += 2 {
		fmt.Scanf("%d %d\n", &a[i], &a[i+1])
	}

	ans := AbsInt(a[2]-a[0]) + AbsInt(a[3]-a[1])
	if a[0] == a[2] && a[2] == a[4] && (a[1]-a[5])*(a[3]-a[5]) < 0 {
		ans += 2
	} else if a[1] == a[3] && a[3] == a[5] && (a[0]-a[4])*(a[2]-a[4]) < 0 {
		ans += 2
	}
	fmt.Println(ans)
}

func main() {
	var testcase int
	fmt.Scanf("%d\n", &testcase)
	for i := 1; i <= testcase; i++ {
		fmt.Scanf("\n")
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"

	"os"
)

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

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

func abs(n int) int {
	if n >= 0 {
		return n
	} else {
		return n * (-1)
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var xa, ya, xb, yb, xf, yf int
		fmt.Fscan(input, &xa)
		fmt.Fscan(input, &ya)
		fmt.Fscan(input, &xb)
		fmt.Fscan(input, &yb)
		fmt.Fscan(input, &xf)
		fmt.Fscan(input, &yf)

		var d int = abs(xb - xa) + abs(yb-ya)

		if xa == xb {
			if xa != xf {
				fmt.Println(d)
			} else {
				if MIN(ya,yb) < yf && yf < MAX(ya,yb) {
					fmt.Println(d+2)
				} else {
					fmt.Println(d)
				}
			}
		} else {
			if ya == yb {
				if ya != yf {
					fmt.Println(d)
				} else {
					if MIN(xa,xb) < xf && xf < MAX(xa,xb) {
						fmt.Println(d+2)
					} else {
						fmt.Println(d)
					}
				}
			}else{
				fmt.Println(d)
			}
		}

	}
}

package main

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

func shortestPath(p []Point) int {
	path := 0
	dx := abs(p[0].x - p[1].x)
	dy := abs(p[0].y - p[1].y)
	path = dx + dy
	minx, maxx := min(p[0].x, p[1].x)
	miny, maxy := min(p[0].y, p[1].y)
	if (p[0].x == p[2].x && p[1].x == p[2].x && (p[2].y > miny && p[2].y < maxy)) ||
		(p[0].y == p[2].y && p[1].y == p[2].y && (p[2].x > minx && p[2].x < maxx)) {
		path += 2
	}
	return path
}

type Point struct {
	x, y int
}

func min(x, y int) (int, int) {
	if x < y {
		return x, y
	}
	return y, x
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func parse(s *bufio.Scanner) []Point {
	points := make([]Point, 3)
	s.Scan()
	var x, y int
	for i := 0; i < 3; i++ {
		s.Scan()
		fmt.Sscan(s.Text(), &x, &y)
		points[i] = Point{x, y}
	}

	return points
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	t, _ := strconv.Atoi(s.Text())
	for i := 0; i < t; i++ {
		points := parse(s)
		pathLength := shortestPath(points)
		fmt.Println(pathLength)
	}
}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		getString(reader)
		A := getIntln(reader)
		B := getIntln(reader)
		F := getIntln(reader)
		var res int

		if A[0] == B[0] && A[0] == F[0] && isBetween(A[1], F[1], B[1]) {
			res = 2
		} else if A[1] == B[1] && A[1] == F[1] && isBetween(A[0], F[0], B[0]) {
			res = 2
		}
		res += mod(A[1]-B[1]) + mod(A[0]-B[0])
		writer.WriteString(fmt.Sprintln(res))
	}
	writer.Flush()
}

func isBetween(a, b, c int) bool {
	if b >= a && b <= c {
		return true
	}
	if b >= c && b <= a {
		return true
	}
	return false
}

func mod(a int) int {
	if a < 0 {
		return -1 * a
	} else {
		return a
	}
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var ax, ay, bx, by, fx, fy int
		fmt.Fscan(in, &ax, &ay, &bx, &by, &fx, &fy)

		tot := abs(ax-bx) + abs(ay-by)
		if ax == bx && ax == fx && fy > min(ay, by) && fy < max(ay, by) {
			tot += 2
		}

		if ay == by && ay == fy && fx > min(ax, bx) && fx < max(ax, bx) {
			tot += 2
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	x, y   [3]int
)

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

func solve(x, y [3]int) int {
	var d int
	if x[0] == x[1] {
		d = abs(y[0] - y[1])
		if x[2] == x[0] && (y[2]-y[0])*(y[2]-y[1]) < 0 {
			d += 2
		}
		return d
	}
	if y[0] == y[1] {
		d = abs(x[0] - x[1])
		if y[2] == y[0] && (x[2]-x[0])*(x[2]-x[1]) < 0 {
			d += 2
		}
		return d
	}
	return abs(x[0]-x[1]) + abs(y[0]-y[1])
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		for i := 0; i < 3; i++ {
			fmt.Fscan(reader, &x[i], &y[i])
		}
		fmt.Println(solve(x, y))
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1547A
Date: 11/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1547/A
Problem: CF1547A
**/
func (in *CF1547A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		in.NextString()
		ax, ay := in.NextInt(), in.NextInt()
		bx, by := in.NextInt(), in.NextInt()
		fx, fy := in.NextInt(), in.NextInt()
		sol := 0
		if ax == bx {
			min := Min(ay, by)
			max := Max(ay, by)
			sol = max - min
			if ax == fx && min <= fy && fy <= max {
				sol += 2
			}
		} else if ay == by {
			min := Min(ax, bx)
			max := Max(ax, bx)
			sol = max - min
			if ay == fy && min <= fx && fx <= max {
				sol += 2
			}
		} else {
			sol = int(math.Abs(float64(ax-bx))) + int(math.Abs(float64(ay-by)))
		}
		fmt.Println(sol)
	}
}

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

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

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

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

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var a, b, c [2]int
		Fscan(in, &a[0], &a[1], &b[0], &b[1], &c[0], &c[1])

		ManhattanPath := abs(a[0] - b[0]) + abs(a[1] - b[1])
		minX, maxX := min(a[0], b[0]), max(a[0], b[0])
		minY, maxY := min(a[1], b[1]), max(a[1], b[1])

		if a[0] == b[0] && c[0] == a[0] {
			if minY < c[1] && c[1] < maxY {
				ManhattanPath += 2
			}

		} else if a[1] == b[1] && c[1] == a[1] {
			if minX < c[0] && c[0] < maxX {
				ManhattanPath += 2
			}
		}
		Fprintln(out, ManhattanPath)
	}

}

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var (
		xa, ya, xb, yb, xf, yf, t int
	)
	fmt.Scan(&t)
	for i:=0;i<t;i++ {
		fmt.Scan(&xa, &ya, &xb, &yb, &xf, &yf)
		if aligned(xa, xb, xf, ya, yb, yf) || aligned(ya, yb, yf, xa, xb, xf) {
			fmt.Println(abs(xa-xb) + abs(ya-yb)+2)
		} else {
			fmt.Println(abs(xa-xb) + abs(ya-yb))
		}
	}
}

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

func aligned(x1, x2, x3, x4, x5, x6 int) bool {
	return equal(x1, x2, x3) && between(x4, x5, x6)
}

func equal(x1, x2, x3 int) bool {
	return x1 == x2 && x1 == x3
}

func between(x1, x2, x3 int) bool {
	return (x1 < x3) == (x3 < x2)
}

package main

import (
	"fmt"
)

type Point struct {
	x,y int
}

var t, ans int
var A, B, F Point

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

func swap(a, b *int) {
	tmp := *a
	*a = *b
	*b = tmp
}

func in(a, b, c int ) bool {
	if a > b { swap(&a,&b) }
	if a <= c && c <= b { return true }
	return false
}

func isFailWay(A, B, C Point) bool {
	if A.x == B.x && B.x == C.x && in(A.y,B.y,C.y) { return true }
	if A.y == B.y && B.y == C.y && in(A.x,B.x,C.x) { return true }
	return false
}

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

	for i := 0; i < t; i++ {
		fmt.Scanln()

		fmt.Scan(&A.x, &A.y)
		fmt.Scan(&B.x, &B.y)
		fmt.Scan(&F.x, &F.y)

		ans = abs(A.x-B.x)+abs(A.y-B.y)

		if isFailWay(A,B,F) { ans+=2 }

		fmt.Println(ans)
	}

}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var XA, YA, XB, YB, XF, YF int

		fmt.Fscan(input, &XA, &YA, &XB, &YB, &XF, &YF)

		if (XA-XB)*(YB-YA) != 0 {
			fmt.Println(MODULE(XA, XB) + MODULE(YA, YB))
		} else {
			if XA == XB && YA == YB {
				fmt.Println(0)
			} else {
				if XA == XB {
					if XF == XA && MODULE(YF, YB)+MODULE(YF, YA) == MODULE(YA, YB) {
						fmt.Println(MODULE(YA, YB) + 2)
					} else {
						fmt.Println(MODULE(YA, YB))
					}
				} else {
					if YF == YA && MODULE(XF, XB)+MODULE(XF, XA) == MODULE(XA, XB) {
						fmt.Println(MODULE(XA, XB) + 2)
					} else {
						fmt.Println(MODULE(XA, XB))
					}
				}
			}
		}

	}

}

package main

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

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

	solve := func(Case int) (ans int) {
		var xa, ya, xb, yb, xf, yf int
		Fscan(in, &xa, &ya, &xb, &yb, &xf, &yf)

		if xa == xb && ya == yb {
			return
		}
		if xa == xb && xb == xf {
			if judge(ya, yb, yf) {
				ans += 2
			}
		}
		if ya == yb && yb == yf {
			if judge(xa, xb, xf) {
				ans += 2
			}
		}
		ans += abs(xa-xb) + abs(ya-yb)
		return
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		Fprintln(out, solve(Case))
	}

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

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

func judge(x, y, z int) bool {
	if x > y {
		x, y = y, x
	}
	return x < z && z < y
}

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

package main

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

const MOD = 1000000007

var (
	in  *bufio.Reader
	out *bufio.Writer
)

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

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

	for tc := 1; tc <= t; tc++ {
		solveTest(tc)
	}

	out.Flush()
}

func solveTest(tc int) {
	var xa, ya, xb, yb, xf, yf int
	fmt.Fscan(in, &xa)
	fmt.Fscan(in, &ya)
	fmt.Fscan(in, &xb)
	fmt.Fscan(in, &yb)
	fmt.Fscan(in, &xf)
	fmt.Fscan(in, &yf)

	var answer int
	answer = abs(xa - xb) + abs(ya - yb)
	if xa == xb && min(ya, yb) <= yf && yf <= max(ya, yb) && xa == xf {
		answer += 2
	}
	if ya == yb && min(xa, xb) <= xf && xf <= max(xa, xb) && ya == yf {
		answer += 2
	}
	fmt.Fprintln(out, answer)
}

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

func min(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result > xs[i] {
			result = xs[i]
		}
	}
	return result
}

func max(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result < xs[i] {
			result = xs[i]
		}
	}
	return result
}

package main

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

func solve(r io.Reader) {
	var n int
	var s string
	var t []string

	reader := bufio.NewReader(r)
	s, _ = reader.ReadString('\n')
	s = strings.TrimSpace(s)
	n, _ = strconv.Atoi(s)

	for i := 0; i < n; i++ {
		_, _ = reader.ReadString('\n')
		x := make([][]int, 3)
		for j := 0; j < 3; j++ {
			s, _ = reader.ReadString('\n')
			s = strings.TrimSpace(s)
			t = strings.Split(s, " ")
			x1, _ := strconv.Atoi(t[0])
			x2, _ := strconv.Atoi(t[1])
			x[j] = []int{x1, x2}
		}

		xa := x[0][0]
		xb := x[0][1]

		ya := x[1][0]
		yb := x[1][1]

		fa := x[2][0]
		fb := x[2][1]

		p0 := xa - ya
		if p0 < 0 {
			p0 = -p0
		}
		p1 := xb - yb
		if p1 < 0 {
			p1 = -p1
		}
		p2 := 0
		if xa == ya && xa == fa &&
			((xb > fb && fb > yb) || (yb > fb && fb > xb)) {
			p2 = 2
		} else if xb == yb && xb == fb &&
			((xa > fa && fa > ya) || (ya > fa && fa > xa)) {
			p2 = 2
		}
		fmt.Println(p0 + p1 + p2)
	}
}

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

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var xa, ya, xb, yb, xf, yf int
		_, _ = fmt.Fscan(in, &xa, &ya, &xb, &yb, &xf, &yf)

		var ans int
		if (xa == xb && xb == xf) && (yf > min(ya, yb) && yf < max(ya, yb)) {
			ans = 2
		}

		if (ya == yb && yb == yf) && (xf > min(xa, xb) && xf < max(xa, xb)) {
			ans = 2
		}

		ans += abs(xb-xa) + abs(yb-ya)

		_, _ = fmt.Fprintln(out, ans)
	}

	_ = out.Flush()
}

func abs(n int) int {
	if n < 0 {
		n = -n
	}

	return n
}

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

	return b
}

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

	return b
}

package main

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

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

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

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		ax, ay := sint64(), sint64()
		bx, by := sint64(), sint64()
		fx, fy := sint64(), sint64()
		printf("%d\n", sol(ax, ay, bx, by, fx, fy))
	}
}

func sol(ax, ay, bx, by, fx, fy int64) int64 {
	ret := abs(ay-by) + abs(ax-bx)
	if (ax == fx && bx == fx && between(ay, by, fy)) || (ay == fy && by == fy && between(ax, bx, fx)) {
		ret += 2
	}
	return ret
}

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

func between(a, b, f int64) bool {
	if a < f && f < b {
		return true
	}
	if b < f && f < a {
		return true
	}
	return false
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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 abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func rast(ax, ay, bx, by int) int {
	return abs(ax-bx) + abs(ay-by)
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
	for ; t > 0; t-- {
		io.ReadString()
		ax, ay := io.ReadPairInt()
		bx, by := io.ReadPairInt()
		cx, cy := io.ReadPairInt()
		ans := rast(ax, ay, bx, by)
		if (cx == ax && ax == bx || cy == ay && ay == by) && rast(ax, ay, cx, cy) + rast(bx, by, cx, cy) == ans{
			ans += 2
		}
		io.Println(ans)
	}
}

package main

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

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

	solve := func(Case int) {
		var xa, ya, xb, yb, xf, yf int
		Fscan(in, &xa, &ya, &xb, &yb, &xf, &yf)

		if ya == yb {
			xa, ya = ya, xa
			xb, yb = yb, xb
			xf, yf = yf, xf
		}

		ans := 0
		if xa == xb {
			if ya > yb {
				ya, yb = yb, ya
			}
			if xf == xa {
				if ya < yf && yf < yb {
					ans = 2
				}
			}
		}
		ans+=abs(xa-xb)+abs(ya-yb)
		Fprintln(out, ans)
	}

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

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

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

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

package main

import (
	"fmt"
	"math"
)

type Point struct {
	x, y int
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var a, b, f Point
		fmt.Scanf("\n%d%d\n", &a.x, &a.y)
		fmt.Scanf("%d%d\n", &b.x, &b.y)
		fmt.Scanf("%d%d\n", &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			ans = int(math.Abs(float64(a.y - b.y)))
			if a.y > b.y {
				a.y, b.y = b.y, a.y
			}
			if f.x == a.x && f.y > a.y && f.y < b.y {
				ans += 2
			}
		} else if a.y == b.y {
			ans = int(math.Abs(float64(a.x-b.x))) + 2
			if a.x > b.x {
				a.x, b.x = b.x, a.x
			}
			if f.y == a.y && f.x > a.x && f.x < b.x {
				ans += 2
			}
		} else {
			ans = int(math.Abs(float64(a.x-b.x))) + int(math.Abs(float64(a.y-b.y)))
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"math"
)

type Point struct {
	x, y int
}

func main() {
	T := 0
	fmt.Scanf("%d", &T)
	for ; T > 0; T-- {
		var a, b, f Point
		fmt.Scanf("%d%d", &a.x, &a.y)
		fmt.Scanf("%d%d", &b.x, &b.y)
		fmt.Scanf("%d%d", &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			ans = int(math.Abs(float64(a.y - b.y)))
			if f.x == a.x {
				ans += 2
			}
		} else if a.y == b.y {
			ans = int(math.Abs(float64(a.x-b.x))) + 2
			if f.y == a.y {
				ans += 2
			}
		} else {
			ans = int(math.Abs(float64(a.x-b.x))) + int(math.Abs(float64(a.y-b.y)))
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"math"
)

type Point struct {
	x, y int
}

func main() {
	T := 0
	fmt.Scanf("%d", &T)
	for ; T > 0; T-- {
		var a, b, f Point
		fmt.Scanf("%d%d", &a.x, &a.y)
		fmt.Scanf("%d%d", &b.x, &b.y)
		fmt.Scanf("%d%d", &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			ans = int(math.Abs(float64(a.y-b.y))) + 2
		} else if a.y == b.y {
			ans = int(math.Abs(float64(a.x-b.x))) + 2
		} else {
			ans = int(math.Abs(float64(a.x-b.x))) + int(math.Abs(float64(a.y-b.y)))
		}

		fmt.Println(ans)
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var ax,ay int
		fmt.Scan(&ax,&ay)
		var bx,by int
		fmt.Scan(&bx,&by)
		var cx,cy int
		fmt.Scan(&cx,&cy)
		if ax == bx {
			if cy > min(ay,by) && cy < max(ay,by) {
				fmt.Println(abs(ay-by)+2)
				continue
			}
		} else if ay == by {
			if cx > min(ax,bx) && cx < max(ax,bx) {
				fmt.Println(abs(ax-bx)+2)
				continue
			}
		}
		fmt.Println(abs(ax-bx)+abs(ay-by))
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var ax,ay int
		fmt.Scan(&ax,&ay)
		var bx,by int
		fmt.Scan(&bx,&by)
		var cx,cy int
		fmt.Scan(&cx,&cy)
		if ax == bx {
			if cy > min(ay,by) && cy < max(ay,by) {
				fmt.Println(abs(ay-by)+2)
				break
			}
		} else if ay == by {
			if cx > min(ax,bx) && cx < max(ax,bx) {
				fmt.Println(abs(ax-bx)+2)
				break
			}
		}
		fmt.Println(abs(ax-bx)+abs(ay-by))
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var ax,ay int
		fmt.Scan(&ax,&ay)
		var bx,by int
		fmt.Scan(&bx,&by)
		var cx,cy int
		fmt.Scan(&cx,&cy)
		if (cx > min(ax,bx) && cx < max(ax,bx)) || (cy > min(ay,by) && cy < max(ay,by)) {
			if abs(bx-ax) > 0 {
				fmt.Println(abs(bx-ax)+2)
			} else {
				fmt.Println(abs(by-ay)+2)
			}
		} else {
			if abs(bx-ax) > 0 {
				if abs(by-ay) > 0 {
					fmt.Println(abs(bx-ax)+1)
				} else {
					fmt.Println(abs(bx-ax))
				}
			} else {
				if abs(bx-ax) > 0 {
					fmt.Println(abs(by-ay)+1)
				} else {
					fmt.Println(abs(by-ay))
				}
			}
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var ax,ay int
		fmt.Scan(&ax,&ay)
		var bx,by int
		fmt.Scan(&bx,&by)
		var cx,cy int
		fmt.Scan(&cx,&cy)
		if (cx > min(ax,bx) && cx < max(ax,bx)) || (cy > min(ay,by) && cy < max(ay,by)) {
			if abs(bx-ax) > 0 {
				fmt.Println(abs(bx-ax)+2)
			} else {
				fmt.Println(abs(by-ay)+2)
			}
		} else {
			if abs(bx-ax) > 0 {
				fmt.Println(abs(bx-ax))
			} else {
				fmt.Println(abs(by-ay))
			}
		}
	}
}
func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main

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

type pair struct{
	x,y int
}

func judge(a,b,f int) bool {
	if((f>a&&f<b)||(f>b&&f<a) ) {
		return true
	}
	return false
}

func main() {
	var T int;
	fmt.Scanln(&T)
	for i:=0;i<T;i++ {
		var a,b,f pair
		fmt.Fscan(os.Stdin,&a.x,&a.y,&b.x,&b.y,&f.x,&f.y)

		if (a.x==b.x&&a.x==f.x&&judge(a.x,b.x,f.x))||(a.y==b.y&&a.y==f.y&&judge(a.y,b.y,f.y)) {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))+2))

		}else {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))))
		}
	}
}

package main

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

type pair struct{
	x,y int
}

func main() {
	var T int;
	fmt.Scanln(&T)
	for i:=0;i<T;i++ {
		var a,b,f pair
		fmt.Fscan(os.Stdin,&a.x,&a.y,&b.x,&b.y,&f.x,&f.y)

		if a.x==b.x || a.y == b.y {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))+2))

		}else {
			fmt.Println(int(math.Abs(float64(a.x)-float64(b.x))+math.Abs(float64(a.y)-float64(b.y))))
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	_, err := fmt.Scanf("%d\n",&t)
	if err != nil {
		return
	}
	for i := int64(0); i < t; i++ {
		var Ax int64
		var Ay int64
		var Bx int64
		var By int64
		var Fx int64
		var Fy int64
		_, err := fmt.Scanf("\n%d %d\n", &Ax, &Ay)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Bx, &By)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Fx, &Fy)
		if err != nil {
			return
		}
		pathLen := math.Abs(float64(Ax-Bx)) + math.Abs(float64(Ay-By))
		if (Ax == Bx && Ax == Fx) || (Ay == By && Ay == Fy) {
			pathLen += 2
			fmt.Println(int64(pathLen))
		} else {
			fmt.Println(int64(pathLen))
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}
	for i := int64(0); i < t; i++ {
		var Ax int64
		var Ay int64
		var Bx int64
		var By int64
		var Fx int64
		var Fy int64
		_, err := fmt.Scanf("\n%d %d\n", &Ax, &Ay)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Bx, &By)
		if err != nil {
			return
		}
		_, err = fmt.Scanf("%d %d\n", &Fx, &Fy)
		if err != nil {
			return
		}
		pathLen := math.Abs(float64(Ax-Bx)) + math.Abs(float64(Ay-By))
		if (Ax == Bx && Ax == Fx) || (Ay == By && Ay == Fy) {
			pathLen += 2
			fmt.Println(int64(pathLen))
		} else {
			fmt.Println(int64(pathLen))
		}
	}
}

package main

import "fmt"

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

func algo(testcases [][3][2]int) {
	for _, test_case := range testcases {
		row_diff := abs(test_case[0][0] - test_case[1][0])
		col_diff := abs(test_case[0][1] - test_case[1][1])
		ans := row_diff + col_diff

		if row_diff == 0 {
			a := test_case[0][1] - test_case[2][1]
			b := test_case[1][1] - test_case[2][1]
			if a^b < 0 {
				ans += 2
			}
		} else if col_diff == 0 {
			a := test_case[0][0] - test_case[2][0]
			b := test_case[1][0] - test_case[2][0]
			if a^b < 0 {
				ans += 2
			}
		}
		fmt.Println(ans)
	}
}

func input() [][3][2]int {
	num_case := 0
	fmt.Scanln(&num_case)
	testcases := make([][3][2]int, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scanf("\n")
		for j := 0; j < 3; j++ {
			fmt.Scanf("%d %d\n", &testcases[i][j][0], &testcases[i][j][1])
		}
	}

	return testcases
}

func main() {
	testcases := input()
	algo(testcases)
}

package main

import "fmt"

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

func algo(testcases [][3][2]int) {
	for _, test_case := range testcases {
		row_diff := abs(test_case[0][0] - test_case[1][0])
		col_diff := abs(test_case[0][1] - test_case[1][1])
		ans := row_diff + col_diff

		if row_diff == 0 {
			a := test_case[0][1] - test_case[2][1]
			b := test_case[1][1] - test_case[2][1]
			if a^b < 0 {
				ans += 2
			}
		} else if col_diff == 0 {
			a := test_case[0][0] - test_case[2][0]
			b := test_case[1][0] - test_case[2][0]
			if a^b < 0 {
				ans += 2
			}
		}
		fmt.Println(ans)
	}
}

func input() [][3][2]int {
	num_case := 0
	fmt.Scan(&num_case)
	testcases := make([][3][2]int, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scanf("\n")
		for j := 0; j < 3; j++ {
			fmt.Scanf("%d %d\n", &testcases[i][j][0], &testcases[i][j][1])
		}
	}

	return testcases
}

func main() {
	testcases := input()
	algo(testcases)
}

package main

import (
	"fmt"
)

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

func solve() {
	a := make([]int, 6)
	for i := 0; i < 6; i += 2 {
		fmt.Scanf("%d %d\n", &a[i], &a[i+1])
	}

	ans := AbsInt(a[2]-a[0]) + AbsInt(a[3]-a[1])
	if a[0] == a[2] && a[2] == a[4] && (a[1]-a[5])*(a[3]-a[5]) < 0 {
		ans += 2
	} else if a[1] == a[3] && a[3] == a[5] && (a[0]-a[4])*(a[2]-a[4]) < 0 {
		ans += 2
	}
	fmt.Println(ans)
}

func main() {
	var testcase int
	fmt.Scanf("%d\n", &testcase)
	for i := 1; i <= testcase; i++ {
		//fmt.Scanf("\n")
		solve()
	}
}

package main

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

func MIN(x int64, y int64) int64 {
	if x > y{
		return y
	}else{
		return x
	}
}

func MAX(x int64, y int64) int64 {
	if x > y{
		return x
	}else{
		return y
	}
}

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

var p int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &p)
	for o := 0; o < p; o++ {
		var xa, xb, xf, ya, yb, yf int64
		fmt.Fscan(input, &xa)
		fmt.Fscan(input, &ya)
		fmt.Fscan(input, &xb)
		fmt.Fscan(input, &yb)
		fmt.Fscan(input, &xf)
		fmt.Fscan(input, &yf)

		var ans int64

		dis := ABS(xa - xb) + ABS(ya - yb)

		if xa == xb && xb == xf{
			if MIN(ya,yb) < yf && yf < MAX(ya,yb){
				ans = dis + 2
			}else{
				ans = dis
			}
		}else if ya == yb && yb == yf{
			if MIN(xa,xb) < xf  && xf < MAX(ya,yb){
				ans = dis + 2
			}else{
				ans = dis
			}
		}else{
			ans = dis
		}

		fmt.Println(ans)
	}
}

package main

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

func shortestPath(p []Point) int {
	path := 0
	dx := abs(p[0].x - p[1].x)
	dy := abs(p[0].y - p[1].y)
	path = dx + dy
	if (p[0].x == p[2].x && p[1].x == p[2].x && !(p[2].x > p[0].x && p[2].x > p[1].x)) ||
		(p[0].y == p[2].y && p[1].y == p[2].y && !(p[2].y > p[0].y && p[2].y > p[1].y)) {
		path += 2
	}
	return path
}

type Point struct {
	x, y int
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func parse(s *bufio.Scanner) []Point {
	points := make([]Point, 3)
	s.Scan()
	var x, y int
	for i := 0; i < 3; i++ {
		s.Scan()
		fmt.Sscan(s.Text(), &x, &y)
		points[i] = Point{x, y}
	}

	return points
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	t, _ := strconv.Atoi(s.Text())
	for i := 0; i < t; i++ {
		points := parse(s)
		pathLength := shortestPath(points)
		fmt.Println(pathLength)
	}
}


There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

package main

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

type Node struct {
	max int
	min int
}

var n int
var h [100000]int

func create(tree []*Node, l int, r int, index int) {
	if l == r {
		tree[index] = &Node{h[l], h[r]}
		return
	}
	mid := (l + r) / 2
	create(tree, l, mid, index*2+1)
	create(tree, mid+1, r, index*2+2)
	max, min := tree[index*2+1].max, tree[index*2+1].min
	if max < tree[index*2+2].max {
		max = tree[index*2+2].max
	}
	if min > tree[index*2+2].min {
		min = tree[index*2+2].min
	}
	tree[index] = &Node{max, min}
}

func query(tree []*Node, l int, r int, index int, lIndex int, rIndex int) (int, int) {
	if l == lIndex && r == rIndex {
		return tree[index].max, tree[index].min
	}
	mid := (l + r) / 2
	if rIndex <= mid {
		return query(tree, l, mid, index*2+1, lIndex, rIndex)
	}
	if lIndex >= mid+1 {
		return query(tree, mid+1, r, index*2+2, lIndex, rIndex)
	}
	max, min := query(tree, l, mid, index*2+1, lIndex, mid)
	max1, min1 := query(tree, mid+1, r, index*2+2, mid+1, rIndex)
	if max < max1 {
		max = max1
	}
	if min > min1 {
		min = min1
	}
	return max, min
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n, k int

	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &h[i])
	}
	tree := make([]*Node, 1000000)
	create(tree, 0, n-1, 0)

	lp, rp := 0, 0
	best := 0
	var solu []*Node = make([]*Node, 100000, 100000)
	var sLen int
	var max, min int
	for rp != n {
		for {
			max, min = query(tree, 0, n-1, 0, lp, rp)
			if max-min > k {
				lp++
			} else {
				break
			}
		}
		for {
			if best == rp-lp+1 {
				solu[sLen] = &Node{rp, lp}
				sLen++
				rp++
			} else if best < rp-lp+1 {
				best = rp - lp + 1
				solu[0] = &Node{rp, lp}
				sLen = 1
				rp++
			} else {
				rp++
			}
			if rp != n {
				if max < h[rp] {
					max = h[rp]
				}
				if min > h[rp] {
					min = h[rp]
				}
				if max-min > k {
					break
				}
			} else {
				break
			}
		}
		if rp == n {
			break
		}
	}

	writer := bytes.NewBuffer(make([]byte, 0, 12000000))

	fmt.Fprintf(writer, "%d %d\n", best, sLen)
	for i := 0; i < sLen; i++ {
		fmt.Fprintf(writer, "%d %d\n", solu[i].min+1, solu[i].max+1)
	}
	writer.WriteTo(os.Stdout)

}

package main

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

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

	n, k := readTwoNums(reader)

	H := readNNums(reader, n)

	a, b := solve(n, k, H)
	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d %d\n", a, len(b)))

	for i := 0; i < len(b); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", b[i][0], b[i][1]))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

const N_INF = -(10000000)

func solve(n, k int, H []int) (a int, b [][]int) {
	get := func(l, r int, arr []int) int {
		res := N_INF

		l += n
		r += n

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	x := make([]int, 2*n)
	y := make([]int, 2*n)

	for i := n; i < 2*n; i++ {
		x[i] = H[i-n]
		y[i] = -H[i-n]
	}

	for i := n - 1; i > 0; i-- {
		x[i] = max(x[2*i], x[2*i+1])
		y[i] = max(y[2*i], y[2*i+1])
	}

	getDiff := func(i, j int) int {
		xx := get(i, j, x)
		yy := -get(i, j, y)
		return xx - yy
	}

	check := func(l int) bool {
		for i := 0; i+l <= n; i++ {
			d := getDiff(i, i+l)
			if d <= k {
				return true
			}
		}
		return false
	}

	var left, right = 0, n + 1

	for left < right {
		mid := (left + right) / 2
		if !check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	a = right - 1

	for i := 0; i+a <= n; i++ {
		d := getDiff(i, i+a)
		if d <= k {
			b = append(b, []int{i + 1, i + a})
		}
	}
	return
}

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

package main

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

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

	n, k := readTwoNums(reader)

	H := readNNums(reader, n)

	a, b := solve(n, k, H)
	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d %d\n", a, len(b)))

	for i := 0; i < len(b); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", b[i][0], b[i][1]))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

const N_INF = -(10000000)

func solve(n, k int, H []int) (a int, b [][]int) {
	get := func(l, r int, arr []int) int {
		res := N_INF

		l += n
		r += n

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	x := make([]int, 2*n)
	y := make([]int, 2*n)

	for i := n; i < 2*n; i++ {
		x[i] = H[i-n]
		y[i] = -H[i-n]
	}

	for i := n - 1; i > 0; i-- {
		x[i] = max(x[2*i], x[2*i+1])
		y[i] = max(y[2*i], y[2*i+1])
	}

	getDiff := func(i, j int) int {
		xx := get(i, j, x)
		yy := -get(i, j, y)
		return xx - yy
	}

	for i, j := 0, 1; j <= n; j++ {
		for i < j && getDiff(i, j) > k {
			i++
		}
		if j-i > a {
			a = j - i
		}
	}

	for i := 0; i+a <= n; i++ {
		d := getDiff(i, i+a)
		if d <= k {
			b = append(b, []int{i + 1, i + a})
		}
	}
	return
}

func solve1(n, k int, H []int) (a int, b [][]int) {
	get := func(l, r int, arr []int) int {
		res := N_INF

		l += n
		r += n

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	x := make([]int, 2*n)
	y := make([]int, 2*n)

	for i := n; i < 2*n; i++ {
		x[i] = H[i-n]
		y[i] = -H[i-n]
	}

	for i := n - 1; i > 0; i-- {
		x[i] = max(x[2*i], x[2*i+1])
		y[i] = max(y[2*i], y[2*i+1])
	}

	getDiff := func(i, j int) int {
		xx := get(i, j, x)
		yy := -get(i, j, y)
		return xx - yy
	}

	check := func(l int) bool {
		for i := 0; i+l <= n; i++ {
			d := getDiff(i, i+l)
			if d <= k {
				return true
			}
		}
		return false
	}

	var left, right = 0, n + 1

	for left < right {
		mid := (left + right) / 2
		if !check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}
	a = right - 1

	for i := 0; i+a <= n; i++ {
		d := getDiff(i, i+a)
		if d <= k {
			b = append(b, []int{i + 1, i + a})
		}
	}
	return
}

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