There are $$$n$$$ piles of sand where the $$$i$$$-th pile has $$$a_i$$$ blocks of sand. The $$$i$$$-th pile is called too tall if $$$1 < i < n$$$ and $$$a_i > a_{i-1} + a_{i+1}$$$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.)You are given an integer $$$k$$$. An operation consists of picking $$$k$$$ consecutive piles of sand and adding one unit of sand to them all. Formally, pick $$$1 \leq l,r \leq n$$$ such that $$$r-l+1=k$$$. Then for all $$$l \leq i \leq r$$$, update $$$a_i \gets a_i+1$$$.What is the maximum number of piles that can simultaneously be too tall after some (possibly zero) operations?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq k \leq n$$$) — the number of piles of sand and the size of the operation, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sizes of the piles. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the maximum number of piles that are simultaneously too tall after some (possibly zero) operations.

NoteIn the first test case, we can perform the following three operations:   Add one unit of sand to piles $$$1$$$ and $$$2$$$: $$$[\color{red}{3}, \color{red}{10}, 2, 4, 1]$$$.  Add one unit of sand to piles $$$4$$$ and $$$5$$$: $$$[3, 10, 2, \color{red}{5}, \color{red}{2}]$$$.  Add one unit of sand to piles $$$3$$$ and $$$4$$$: $$$[3, 10, \color{red}{3}, \color{red}{6}, 2]$$$.  Now piles $$$2$$$ and $$$4$$$ are too tall, so in this case the answer is $$$2$$$. It can be shown that it is impossible to make more than $$$2$$$ piles too tall.In the second test case, any operation will increase all piles by $$$1$$$ unit, so the number of too tall piles will always be $$$0$$$.In the third test case, we can increase any pile by $$$1$$$ unit of sand. It can be shown that the maximum number of too tall piles is $$$1$$$.

package main

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

var r = bufio.NewReader(os.Stdin)

func tc() {
	var w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n, k int
	fmt.Fscan(r, &n, &k)

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

	if k > 1 {
		sol := 0
		for i := 1; i < n-1; i++ {
			if a[i] > a[i-1]+a[i+1] {
				sol++
			}
		}
		fmt.Fprintln(w, sol)
	} else {
		fmt.Fprintln(w, (n+1)/2-1)
	}
}

func main() {

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

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

package main

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

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

func tc() {
	var n, k int
	fmt.Fscan(r, &n, &k)

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

	if k > 1 {
		sol := 0
		for i := 1; i < n-1; i++ {
			if a[i] > a[i-1]+a[i+1] {
				sol++
			}
		}
		fmt.Fprintln(w, sol)
	} else {
		fmt.Fprintln(w, (n+1)/2-1)
	}
}

func main() {
	defer w.Flush()

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

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

package main

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

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

func tc() {
	var n, k int
	fmt.Fscan(r, &n, &k)

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

	if k > 1 {
		sol := 0
		for i := 1; i < n-1; i++ {
			if a[i] > a[i-1]+a[i+1] {
				sol++
			}
		}
		fmt.Println(sol)
	} else {
		fmt.Println((n+1)/2 - 1)
	}
}

func main() {
	defer w.Flush()

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

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

package main

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

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		arr := readArrInt(in)
		n, k := arr[0], arr[1]
		piles := readArrInt(in)
		if k == 1 {
			fmt.Println((n - 1) / 2)
		} else {
			ans := 0
			for i := 1; i < n-1; i++ {
				if piles[i] > piles[i+1]+piles[i-1] {
					ans++
				}
			}
			fmt.Println(ans)
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1698B
Date: 4/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1698/B
Problem: CF1698B
**/
func (in *CF1698B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		ans := 0

		if k == 1 {
			ans = int(math.Ceil(float64(n-2) / 2))
		}else {
			for i := 1; i < n-1; i++ {
				if arr[i-1]+arr[i+1] < arr[i] {
					ans++
				}
			}
		}

		fmt.Println(ans)

	}
}

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

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

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

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
	a       []int
)

func solve(n, k int, a []int) int {
	if k == 1 {
		return (n - 1) / 2
	}
	var cnt int
	for i := 1; i < n-1; i++ {
		if a[i] > a[i-1]+a[i+1] {
			cnt++
		}
	}
	return cnt
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; return res }

func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}

func ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); K := gi(); A := gis(N)
		if K == 1 {
			fmt.Fprintln(wrtr,(N-1)/2)
		} else {
			ans := 0
			for i:=1;i+1<N;i++ { if A[i] > A[i-1]+A[i+1] { ans++ } }
			fmt.Fprintln(wrtr,ans)
		}
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		tmp := readArrInt(input)
		n := tmp[0]
		k := tmp[1]
		arr := readArrInt(input)
		fmt.Println(solve(n, k, arr))
	}
}

func solve(n int, k int, arr []int) int {
	if k == 1 {
		return (n - 1) / 2
	} else {
		answer := 0
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i-1]+arr[i+1] {
				answer++
			}
		}
		return answer
	}
	return -1
}

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

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

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

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

package main

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

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

	var nSets int

	_, err := fmt.Fscan(in, &nSets)
	if err != nil {
		os.Exit(2)
	}

	for i := 0; i < nSets; i++ {
		arr, k := ReadSetN(in)
		fmt.Fprintln(out, MaxHuge(arr, k))
	}

	out.Flush()
}

func ReadSetN(in io.Reader) (arr []int, k int) {
	var n int

	_, err := fmt.Fscan(in, &n, &k)
	if err != nil {
		os.Exit(2)
	}

	for i := 0; i < n; i++ {
		tmp := 0
		if _, err = fmt.Fscan(in, &tmp); err != nil {
			os.Exit(2)
		}
		arr = append(arr, tmp)
	}

	return
}

func MaxHuge(arr []int, k int) (res int) {
	if k == 1 {
		return (len(arr) - 1) / 2
	}

	for i := 1; i < len(arr)-1; i++ {
		if arr[i] > arr[i-1]+arr[i+1] {
			res++
		}
	}

	return
}

package main

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

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

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

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

		var tot int
		for i := 1; i < n-1; i++ {
			if aa[i] > aa[i-1]+aa[i+1] {
				tot++
			}
		}
		if k == 1 {
			fmt.Fprintln(out, (n-1)/2)
		} else {
			fmt.Fprintln(out, tot)

		}

	}
}

package main

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

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

func solve() {
	var n, k int
	fmt.Fscan(r, &n, &k)
	piles := make([]int, n)
	for i := range piles {
		fmt.Fscan(r, &piles[i])
	}
	ans := 0
	for i := 1; i < n-1; i++ {
		if piles[i] > piles[i-1]+piles[i+1] {
			ans++
		}
	}
	if k == 1 {
		ans = (n - 1) / 2
	}
	fmt.Fprintln(w, ans)

}
func main() {
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

func slove() {
	var n, k int
	fmt.Fscan(r, &n, &k)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	if k == 1 {
		fmt.Fprintln(w, (n-1)/2)
	} else {
		cnt := 0
		for i:=1;i<n-1;i++ {
			if nums[i] > nums[i-1] + nums[i+1] {
				cnt++
			}
		}
		fmt.Fprintln(w, cnt)
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func tc() {
	var n, k int
	n = readInt()
	k = readInt()

	a := readInts()
	if k > 1 {
		sol := 0
		for i := 1; i < n-1; i++ {
			if a[i] > a[i-1]+a[i+1] {
				sol++
			}
		}
		fmt.Println(sol)
	} else {
		fmt.Println((n+1)/2 - 1)
	}
}

func main() {
	t := 1
	t = readInt()
	for i := 0; i < t; i++ {
		tc()
	}
}

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

package main

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

var in = bufio.NewReader(os.Stdin)

func readInt() int {
	res := 0
	for c, _ := in.ReadByte(); c >= '0' && c <= '9'; c, _ = in.ReadByte() {
		res = res*10 + int(c-'0')
	}
	return res
}

func main() {
	t := readInt()
	for ; t > 0; t-- {
		n, k := readInt(), readInt()
		piles := make([]int, n)
		for i := range piles {
			piles[i] = readInt()
		}
		if k == 1 {
			fmt.Println((n - 1) / 2)
		} else {
			ans := 0
			for i := 1; i < n-1; i++ {
				if piles[i] > piles[i+1]+piles[i-1] {
					ans++
				}
			}
			fmt.Println(ans)
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func readInt() int {
	res := 0
	for c, _ := in.ReadByte(); c >= '0' && c <= '9'; c, _ = in.ReadByte() {
		res = res*10 + int(c-'0')
	}
	return res
}

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		piles := make([]int, n)
		for i := range piles {
			piles[i] = readInt()
		}
		if k == 1 {
			fmt.Println((n - 1) / 2)
		} else {
			ans := 0
			for i := 1; i < n-1; i++ {
				if piles[i] > piles[i+1]+piles[i-1] {
					ans++
				}
			}
			fmt.Println(ans)
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1698B
Date: 4/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1698/B
Problem: CF1698B
**/
func (in *CF1698B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		ans := 0

		if k == 1 {
			ans = int(math.Ceil(float64(n) / 3))
		}else {
			for i := 1; i < n-1; i++ {
				if arr[i-1]+arr[i+1] < arr[i] {
					ans++
				}
			}
		}

		fmt.Println(ans)

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1698B
Date: 4/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1698/B
Problem: CF1698B
**/
func (in *CF1698B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		ans := 0
		for i := 1; i < n-1; i++ {
			if arr[i-1]+arr[i+1] < arr[i] {
				ans++
			} else if  arr[i-1]+arr[i+1] == arr[i]  && k == 1{
				ans++
			}
		}

		fmt.Println(ans)

	}
}

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

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

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


After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.For a given sentence, the cipher is processed as:   Convert all letters of the sentence to lowercase.  Reverse each of the words of the sentence individually.  Remove all the spaces in the sentence. For example, when this cipher is applied to the sentenceKira is childish and he hates losingthe resulting string isariksihsidlihcdnaehsetahgnisolNow Yash is given some ciphered string and a list of words. Help him to find out any original sentence composed using only words from the list. Note, that any of the given words could be used in the sentence multiple times.

The first line of the input contains a single integer n (1 ≤ n ≤ 10 000) — the length of the ciphered text. The second line consists of n lowercase English letters — the ciphered text t. The third line contains a single integer m (1 ≤ m ≤ 100 000) — the number of words which will be considered while deciphering the text. Each of the next m lines contains a non-empty word wi (|wi| ≤ 1 000) consisting of uppercase and lowercase English letters only. It's guaranteed that the total length of all words doesn't exceed 1 000 000.

Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those.

30
ariksihsidlihcdnaehsetahgnisol
10
Kira
hates
is
he
losing
death
childish
L
and
Note

12
iherehtolleh
5
HI
Ho
there
HeLLo
hello

Kira is childish and he hates losing
HI there HeLLo

NoteIn sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF633C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type node struct {
		son [26]*node
		s   []byte
	}

	var n, m int
	var s, t []byte
	root := &node{}
	for Fscan(in, &n, &s, &m); m > 0; m-- {
		Fscan(in, &t)
		o := root
		for i := len(t) - 1; i >= 0; i-- {
			c := t[i]
			if c < 'a' {
				c += 32
			}
			c -= 'a'
			if o.son[c] == nil {
				o.son[c] = &node{}
			}
			o = o.son[c]
		}
		o.s = t
	}

	ans := [][]byte{}
	dp := make([]int8, n)
	var f func(int) int8
	f = func(p int) (res int8) {
		if p == n {
			return 1
		}
		dv := &dp[p]
		if *dv != 0 {
			return *dv
		}
		defer func() { *dv = res }()
		o := root
		for i := p; i < len(s); i++ {
			o = o.son[s[i]-'a']
			if o == nil {
				return -1
			}
			if o.s != nil && f(i+1) == 1 {
				ans = append(ans, o.s)
				return 1
			}
		}
		return -1
	}
	f(0)
	for i := len(ans) - 1; i >= 0; i-- {
		Fprint(out, string(ans[i]), " ")
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"os"
	"runtime/debug"
)

type node struct {
	son [26]*node
	s   string
}

// github.com/EndlessCheng/codeforces-go
func main() {
	debug.SetGCPercent(-1)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, m int
	var s, w string
	root := &node{}
	for Fscan(in, &n, &s, &m); m > 0; m-- {
		Fscan(in, &w)
		o := root
		for _, c := range w {
			if c < 'a' {
				c += 32
			}
			c -= 'a'
			if o.son[c] == nil {
				o.son[c] = &node{}
			}
			o = o.son[c]
		}
		o.s = w
	}

	dp := make([]int8, n)
	var f func(int) int8
	f = func(p int) (res int8) {
		if p < 0 {
			return 1
		}
		dv := &dp[p]
		if *dv != 0 {
			return *dv
		}
		defer func() { *dv = res }()
		o := root
		for i := p; i >= 0; i-- {
			o = o.son[s[i]-'a']
			if o == nil {
				return -1
			}
			if o.s != "" && f(i-1) == 1 {
				Fprint(out, o.s, " ")
				return 1
			}
		}
		return -1
	}
	f(n - 1)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF633C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type node struct {
		son [26]*node
		s   []byte
	}

	var n, m int
	var s, t []byte
	root := &node{}
	for Fscan(in, &n, &s, &m); m > 0; m-- {
		Fscan(in, &t)
		o := root
		for _, c := range t {
			if c < 'a' {
				c += 32
			}
			c -= 'a'
			if o.son[c] == nil {
				o.son[c] = &node{}
			}
			o = o.son[c]
		}
		o.s = t
	}

	dp := make([]int8, n)
	var f func(int) int8
	f = func(p int) (res int8) {
		if p < 0 {
			return 1
		}
		dv := &dp[p]
		if *dv != 0 {
			return *dv
		}
		defer func() { *dv = res }()
		o := root
		for i := p; i >= 0; i-- {
			o = o.son[s[i]-'a']
			if o == nil {
				return -1
			}
			if o.s != nil && f(i-1) == 1 {
				Fprint(out, string(o.s), " ")
				return 1
			}
		}
		return -1
	}
	f(n - 1)
}

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

package main

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

type node struct {
	son [26]*node
	s   string
}

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, m int
	var s, w string
	root := &node{}
	for Fscan(in, &n, &s, &m); m > 0; m-- {
		Fscan(in, &w)
		o := root
		for _, c := range w {
			if c < 'a' {
				c += 32
			}
			c -= 'a'
			if o.son[c] == nil {
				o.son[c] = &node{}
			}
			o = o.son[c]
		}
		o.s = w
	}

	dp := make([]int8, n)
	var f func(int) int8
	f = func(p int) (res int8) {
		if p < 0 {
			return 1
		}
		dv := &dp[p]
		if *dv != 0 {
			return *dv
		}
		defer func() { *dv = res }()
		o := root
		for i := p; i >= 0; i-- {
			o = o.son[s[i]-'a']
			if o == nil {
				return -1
			}
			if o.s != "" && f(i-1) == 1 {
				Fprint(out, o.s, " ")
				return 1
			}
		}
		return -1
	}
	f(n - 1)
}

package main

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

const BASE = 7
const mod = 1e9 + 7
const N = 1000005

var n, m int
var s string
var dp[N] int
var M map[int] string

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

func getLowerValue(x uint8) int {
	if x >= 'A' && x <= 'Z' {
		return int(x - 'A') + 1
	}
	return int(x - 'a') + 1
}

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

func tracing(indx int)  {
	defer writer.Flush()

	if indx == 0 {
		return
	}
	var ans = M[dp[indx]]

	tracing(indx - len(ans))
	fmt.Fprintf(writer, "%s ", ans)
}

func main()  {

	defer writer.Flush()

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

	M = make(map[int]string)

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

	for i := 0; i < m; i++ {
		var t string
		fmt.Fscanf(reader, "%s\n", &t)

		var hashValue = 0
		for j := 0; j < len(t); j++ {
			hashValue = int(int64(hashValue) * int64(BASE) % mod)
			hashValue = (hashValue + getLowerValue(t[j])) % mod
		}
		M[hashValue] = t
	}

	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = -1
		var hashValue = 0
		for j := i; j >= max(i - 999, 1); j-- {
			hashValue = int(int64(hashValue) * int64(BASE) % mod)
			hashValue = (hashValue + int(s[j - 1] - 'a') + 1) % mod
			_, ok := M[hashValue]
			if ok && dp[j - 1] != -1 {
				dp[i] = hashValue
				break
			}
		}
	}

	tracing(n)
}

package main

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

const BASE = 240496
const mod = 1e9 + 7
const N = 1000005

var n, m int
var s string
var dp[N] int
var M map[int] string

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

func getLowerValue(x uint8) int {
	if x >= 'A' && x <= 'Z' {
		return int(x - 'A') + 1
	}
	return int(x - 'a') + 1
}

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

func tracing(indx int)  {
	defer writer.Flush()

	if indx == 0 {
		return
	}
	var ans = M[dp[indx]]

	tracing(indx - len(ans))
	fmt.Fprintf(writer, "%s ", ans)
}

func main()  {

	defer writer.Flush()

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

	M = make(map[int]string)

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

	for i := 0; i < m; i++ {
		var t string
		fmt.Fscanf(reader, "%s\n", &t)

		var hashValue = 0
		for j := 0; j < len(t); j++ {
			hashValue = int(int64(hashValue) * int64(BASE) % mod)
			hashValue = (hashValue + getLowerValue(t[j])) % mod
		}
		M[hashValue] = t
	}

	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = -1
		var hashValue = 0
		for j := i; j >= max(i - 999, 1); j-- {
			hashValue = int(int64(hashValue) * int64(BASE) % mod)
			hashValue = (hashValue + int(s[j - 1] - 'a') + 1) % mod
			_, ok := M[hashValue]
			if ok && dp[j - 1] != -1 {
				dp[i] = hashValue
				break
			}
		}
	}

	tracing(n)
}


Alice and Bob are playing chess on a huge chessboard with dimensions $$$n \times n$$$. Alice has a single piece left — a queen, located at $$$(a_x, a_y)$$$, while Bob has only the king standing at $$$(b_x, b_y)$$$. Alice thinks that as her queen is dominating the chessboard, victory is hers. But Bob has made a devious plan to seize the victory for himself — he needs to march his king to $$$(c_x, c_y)$$$ in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns.Bob will win if he can move his king from $$$(b_x, b_y)$$$ to $$$(c_x, c_y)$$$ without ever getting in check. Remember that a king can move to any of the $$$8$$$ adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen. Find whether Bob can win or not.

The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 1000$$$) — the dimensions of the chessboard. The second line contains two integers $$$a_x$$$ and $$$a_y$$$ ($$$1 \leq a_x, a_y \leq n$$$) — the coordinates of Alice's queen. The third line contains two integers $$$b_x$$$ and $$$b_y$$$ ($$$1 \leq b_x, b_y \leq n$$$) — the coordinates of Bob's king. The fourth line contains two integers $$$c_x$$$ and $$$c_y$$$ ($$$1 \leq c_x, c_y \leq n$$$) — the coordinates of the location that Bob wants to get to. It is guaranteed that Bob's king is currently not in check and the target location is not in check either. Furthermore, the king is not located on the same square as the queen (i.e. $$$a_x \neq b_x$$$ or $$$a_y \neq b_y$$$), and the target does coincide neither with the queen's position (i.e. $$$c_x \neq a_x$$$ or $$$c_y \neq a_y$$$) nor with the king's position (i.e. $$$c_x \neq b_x$$$ or $$$c_y \neq b_y$$$).

Print "YES" (without quotes) if Bob can get from $$$(b_x, b_y)$$$ to $$$(c_x, c_y)$$$ without ever getting in check, otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.In the first case, the king can move, for instance, via the squares $$$(2, 3)$$$ and $$$(3, 2)$$$. Note that the direct route through $$$(2, 2)$$$ goes through check.  In the second case, the queen watches the fourth rank, and the king has no means of crossing it.  In the third case, the queen watches the third file.

package main

import "fmt"

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

func main() {
	var n, ax, ay, bx, by, cx, cy int
	fmt.Scan(&n, &ax, &ay, &bx, &by, &cx, &cy)
	if bx < ax && ax < cx || bx > ax && ax > cx || by < ay && ay < cy || by > ay && ay > cy {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

import (
	"fmt"
	"log"
)

func main() {
	var n int
	var ax, ay int
	var bx, by int
	var cx, cy int

	_, err := fmt.Scan(&n)
	if err != nil {
		log.Fatal(err)
	} else {
		_, err := fmt.Scan(&ax, &ay)
		if err != nil {
			log.Fatal(err)
		}

		_, err = fmt.Scan(&bx, &by)
		if err != nil {
			log.Fatal(err)
		}

		_, err = fmt.Scan(&cx, &cy)
		if err != nil {
			log.Fatal(err)
		}

		res := checkSameQuads(ax, ay, bx, by, cx, cy)

		if res {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

func checkSameQuads(ax, ay, bx, by, cx, cy int) bool {
	if cx < ax {
		if cy < ay {
			if bx < ax && by < ay {
				return true
			}
		} else {
			if bx < ax && by > ay {
				return true
			}
		}
	} else {
		if cy < ay {
			if bx > ax && by < ay {
				return true
			}
		} else {
			if bx > ax && by > ay {
				return true
			}
		}
	}
	return false
}

package main

import (
	"fmt"
)

type coord struct {
	x int64
	y int64
}

func (c1 coord) Add(c2 coord) coord {
	return coord{c1.x + c2.x, c1.y + c2.y}
}

func (c1 coord) Equal(c2 coord) bool {
	return c1.x == c2.x && c1.y == c2.y
}

func (c coord) Valid(n int64, q coord) bool {
	if c.x < 1 || c.y < 1 || c.x > n || c.y > n || c.x == q.x || c.y == q.y || c.x-q.x == c.y-q.y || c.x-q.x == -(c.y-q.y) {
		return false
	}
	return true
}

func (c coord) Neighbors(n int64) []coord {
	ret := []coord{}
	dirs := []coord{{1, 1}, {1, 0}, {1, -1}, {0, 1}, {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}}
	for _, co := range dirs {
		ret = append(ret, c.Add(co))
	}
	return ret
}

type stack []coord

func (s *stack) Push(c coord) {
	*s = append(*s, c)
}

func (s *stack) Pop() coord {
	res := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return res
}

func sol(n int64, a coord, b coord, c coord) string {
	visited := map[coord]bool{}
	tovisit := stack{b}
	for len(tovisit) > 0 {
		curr := tovisit.Pop()
		if visited[curr] {
			continue
		}
		visited[curr] = true
		for _, co := range curr.Neighbors(n) {
			if co.Equal(c) {
				return "YES"
			}
			if co.Valid(n, a) {
				tovisit = append(tovisit, co)
			}
		}

	}
	return "NO"
}

func main() {
	var n, a1, a2, b1, b2, c1, c2 int64
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%d %d\n", &a1, &a2)
	fmt.Scanf("%d %d\n", &b1, &b2)
	fmt.Scanf("%d %d\n", &c1, &c2)
	res := sol(n, coord{a1, a2}, coord{b1, b2}, coord{c1, c2})
	fmt.Println(res)
}


You are given a binary matrix $$$A$$$ of size $$$n \times n$$$. Let's denote an $$$x$$$-compression of the given matrix as a matrix $$$B$$$ of size $$$\frac{n}{x} \times \frac{n}{x}$$$ such that for every $$$i \in [1, n], j \in [1, n]$$$ the condition $$$A[i][j] = B[\lceil \frac{i}{x} \rceil][\lceil \frac{j}{x} \rceil]$$$ is met.Obviously, $$$x$$$-compression is possible only if $$$x$$$ divides $$$n$$$, but this condition is not enough. For example, the following matrix of size $$$2 \times 2$$$ does not have any $$$2$$$-compression: $$$01$$$   $$$10$$$ For the given matrix $$$A$$$, find maximum $$$x$$$ such that an $$$x$$$-compression of this matrix is possible.Note that the input is given in compressed form. But even though it is compressed, you'd better use fast input.

The first line contains one number $$$n$$$ ($$$4 \le n \le 5200$$$) — the number of rows and columns in the matrix $$$A$$$. It is guaranteed that $$$n$$$ is divisible by $$$4$$$. Then the representation of matrix follows. Each of $$$n$$$ next lines contains $$$\frac{n}{4}$$$ one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from $$$0$$$ to $$$9$$$ or as uppercase Latin letters from $$$A$$$ to $$$F$$$). Binary representation of each of these numbers denotes next $$$4$$$ elements of the matrix in the corresponding row. For example, if the number $$$B$$$ is given, then the corresponding elements are 1011, and if the number is $$$5$$$, then the corresponding elements are 0101. Elements are not separated by whitespaces.

Print one number: maximum $$$x$$$ such that an $$$x$$$-compression of the given matrix is possible.

package main

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

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

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

func gcd(a, b int) int {
	var t int
	for b != 0 {
		t = b
		b = a % b
		a = t
	}
	return a
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()
	strs := []string{
		"0000", "0001", "0010", "0011",
		"0100", "0101", "0110", "0111",
		"1000", "1001", "1010", "1011",
		"1100", "1101", "1110", "1111",
	}
	bin := make([][]byte, 16)
	for i, val := range strs {
		bin[i] = []byte(val)
	}

	r := bufio.NewReader(reader)
	// first line: read n
	var n int
	l, _ := r.ReadString(byte('\n'))
	fmt.Sscanf(l, "%d\n", &n)
	var t []byte
	m := make([][]byte, n)
	for i := 0; i < n; i++ {
		tmp := make([]byte, 0, n)
		// t is just a pointer, we need to convert/copy it
		// skip whitespace
		for {
			if c, _, _ := r.ReadRune(); !unicode.IsSpace(c) {
				r.UnreadRune()
				break
			}
		}
		t, _ = r.ReadSlice(byte('\n'))
		// remove newline
		t = t[:len(t)-1]
		// 0 = 48, 9 = 57, A = 65, F = 70
		for _, c := range t {
			if 48 <= c && c <= 57 {
				tmp = append(tmp, bin[c-48]...)
			} else if 65 <= c && c <= 70 {
				tmp = append(tmp, bin[c-55]...)
			}
		}
		m[i] = tmp
	}

	// solution
	g := n
	// iterate over rows
	for i := range m {
		for j := 0; j < n; j++ {
			k := j
			for k < n && m[i][j] == m[i][k] {
				k++
			}
			g = gcd(g, k-j)
			j = k - 1
		}
	}

	// iterate over columns
	for j := 0; j < n; j++ {
		for i := 0; i < n; i++ {
			k := i
			for k < n && m[k][j] == m[i][j] {
				k++
			}
			g = gcd(g, k-i)
			i = k - 1
		}
	}

	printf("%v\n", g)
}

package main

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

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

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

func gcd(a, b int) int {
	var t int
	for b != 0 {
		t = b
		b = a % b
		a = t
	}
	return a
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()
	strs := []string{
		"0000", "0001", "0010", "0011",
		"0100", "0101", "0110", "0111",
		"1000", "1001", "1010", "1011",
		"1100", "1101", "1110", "1111",
	}
	bin := make([][]byte, 16)
	for i, val := range strs {
		bin[i] = []byte(val)
	}

	r := bufio.NewReader(reader)
	// first line: read n
	var n int
	l, _ := r.ReadString(byte('\n'))
	fmt.Sscanf(l, "%d\n", &n)
	var t []byte
	m := make([][]byte, n)
	for i := 0; i < n; i++ {
		tmp := make([]byte, 0, n)
		// t is just a pointer, we need to convert/copy it
		// skip whitespace
		for {
			if c, _, _ := r.ReadRune(); !unicode.IsSpace(c) {
				r.UnreadRune()
				break
			}
		}
		t, _ = r.ReadSlice(byte('\n'))
		// remove newline
		t = t[:len(t)-1]
		// 0 = 48, 9 = 57, A = 65, F = 70
		for _, c := range t {
			if 48 <= c && c <= 57 {
				tmp = append(tmp, bin[c-48]...)
			} else if 65 <= c && c <= 70 {
				tmp = append(tmp, bin[c-55]...)
			}
		}
		m[i] = tmp
		printf("scanned: %v\tlen: %d\n", tmp, len(tmp))
		// skip whitespace
	}

	// solution
	g := n
	// iterate over rows
	for i := range m {
		for j := 0; j < n; j++ {
			k := j
			for k < n && m[i][j] == m[i][k] {
				k++
			}
			g = gcd(g, k-j)
			j = k - 1
		}
	}

	// iterate over columns
	for j := 0; j < n; j++ {
		for i := 0; i < n; i++ {
			k := i
			for k < n && m[k][j] == m[i][j] {
				k++
			}
			g = gcd(g, k-i)
			i = k - 1
		}
	}

	printf("%v\n", g)
}


There are many freight trains departing from Kirnes planet every day. One day on that planet consists of $$$h$$$ hours, and each hour consists of $$$m$$$ minutes, where $$$m$$$ is an even number. Currently, there are $$$n$$$ freight trains, and they depart every day at the same time: $$$i$$$-th train departs at $$$h_i$$$ hours and $$$m_i$$$ minutes.The government decided to add passenger trams as well: they plan to add a regular tram service with half-hour intervals. It means that the first tram of the day must depart at $$$0$$$ hours and $$$t$$$ minutes, where $$$0 \le t < {m \over 2}$$$, the second tram departs $$$m \over 2$$$ minutes after the first one and so on. This schedule allows exactly two passenger trams per hour, which is a great improvement.To allow passengers to board the tram safely, the tram must arrive $$$k$$$ minutes before. During the time when passengers are boarding the tram, no freight train can depart from the planet. However, freight trains are allowed to depart at the very moment when the boarding starts, as well as at the moment when the passenger tram departs. Note that, if the first passenger tram departs at $$$0$$$ hours and $$$t$$$ minutes, where $$$t < k$$$, then the freight trains can not depart during the last $$$k - t$$$ minutes of the day.    A schematic picture of the correct way to run passenger trams. Here $$$h=2$$$ (therefore, the number of passenger trams is $$$2h=4$$$), the number of freight trains is $$$n=6$$$. The passenger trams are marked in red (note that the spaces between them are the same). The freight trains are marked in blue. Time segments of length $$$k$$$ before each passenger tram are highlighted in red. Note that there are no freight trains inside these segments. Unfortunately, it might not be possible to satisfy the requirements of the government without canceling some of the freight trains. Please help the government find the optimal value of $$$t$$$ to minimize the number of canceled freight trains in case all passenger trams depart according to schedule.

The first line of input contains four integers $$$n$$$, $$$h$$$, $$$m$$$, $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le h \le 10^9$$$, $$$2 \le m \le 10^9$$$, $$$m$$$ is even, $$$1 \le k \le {m \over 2}$$$) — the number of freight trains per day, the number of hours and minutes on the planet, and the boarding time for each passenger tram. $$$n$$$ lines follow, each contains two integers $$$h_i$$$ and $$$m_i$$$ ($$$0 \le h_i < h$$$, $$$0 \le m_i < m$$$) — the time when $$$i$$$-th freight train departs. It is guaranteed that no freight trains depart at the same time.

The first line of output should contain two integers: the minimum number of trains that need to be canceled, and the optimal starting time $$$t$$$. Second line of output should contain freight trains that need to be canceled.

NoteIn the first test case of the example the first tram can depart at 0 hours and 0 minutes. Then the freight train at 16 hours and 0 minutes can depart at the same time as the passenger tram, and the freight train at 17 hours and 15 minutes can depart at the same time as the boarding starts for the upcoming passenger tram.In the second test case of the example it is not possible to design the passenger tram schedule without cancelling any of the freight trains: if $$$t \in [1, 15]$$$, then the freight train at 16 hours and 0 minutes is not able to depart (since boarding time is 16 minutes). If $$$t = 0$$$ or $$$t \in [16, 29]$$$, then the freight train departing at 17 hours 15 minutes is not able to depart. However, if the second freight train is canceled, one can choose $$$t = 0$$$. Another possible option is to cancel the first train and choose $$$t = 13$$$.

package main

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

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

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

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

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

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

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

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

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	firstLine := readNNums(reader, 4)
	n, h, m, k := firstLine[0], firstLine[1], firstLine[2], firstLine[3]
	trams := make([][]int, n)
	for i := 0; i < n; i++ {
		trams[i] = readNNums(reader, 2)
	}
	cnt, t, res := solve(n, h, m, k, trams)

	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%d %d\n", cnt, t))

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Println(buf.String())
}

func solve(n int, h int, m int, k int, trams [][]int) (int, int, []int) {
	pp := make([]Pair, 0, 2*n)

	test := make([]int64, 0, 4*n)

	H := int64(h)
	M := int64(m)
	X := H * M
	K := int64(k)
	MOD := M / 2
	for i := 0; i < n; i++ {
		t := (X + int64(trams[i][1])) % MOD
		pp = append(pp, Pair{t, i})
		pp = append(pp, Pair{MOD + t, i})

		test = append(test, (MOD+t-1)%MOD)
		test = append(test, (MOD+t-K)%MOD)
		test = append(test, (t+1)%MOD)
		test = append(test, (t+K)%MOD)
	}

	sort.Sort(Pairs(pp))

	f := func(x, y int64) int {
		i := sort.Search(len(pp), func(i int) bool {
			return pp[i].first > y
		})

		j := sort.Search(len(pp), func(j int) bool {
			return pp[j].first >= x
		})

		return i - j
	}
	var res = math.MaxInt32
	var pos int
	for _, t := range test {
		tmp := f(MOD+t-K+1, MOD+t-1)
		if tmp < res {
			res = tmp
			pos = int(t)
		}
	}

	cancel := make([]int, 0, n)

	for i := 0; i < len(pp); i++ {
		if MOD+int64(pos)-K+1 <= pp[i].first && pp[i].first <= MOD+int64(pos)-1 {
			cancel = append(cancel, pp[i].second+1)
		}
	}

	return res, pos, cancel
}

type Pair struct {
	first  int64
	second int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first < ps[j].first || ps[i].first == ps[j].first && ps[i].second < ps[j].second
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}


Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem. The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.

If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets).

NoteIn the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.In the second example Pasha invents the solution only after the website stops working for the last time.In the third example Pasha sends the solution exactly at the end of the first period.

package main

import (
	"fmt"
)

func readArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a []int
	m int
	l, r []int
)

func read() {
	fmt.Scan(&n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	r = make([]int, m)
	l = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&l[i], &r[i])
	}
}

func main() {
	read()
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	for i := 0; i < m; i++ {
		if sum >= l[i] && sum <= r[i] {
			fmt.Println(sum)
			return
		}
		if sum < l[i] {
			fmt.Println(l[i])
			return
		}
	}
	fmt.Println(-1)
}

package main

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

func check(a []int, t int) bool {
	fmt.Println(a)
	tmp := a[t]
	sort.Ints(a)
	fmt.Println(a)
	if tmp == a[t] {
		return true
	}
	return false
}

func main() {
	var n, summ int
	var input [2]int
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	//n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	line, _ = reader.ReadString('\n')
	for _, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		tmp, _ := strconv.Atoi(j)
		summ += tmp
	}
	line, _ = reader.ReadString('\n')
	n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	for i := 0; i < n; i++ {
		line, _ = reader.ReadString('\n')
		for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
			input[i], _ = strconv.Atoi(j)
		}
		if input[0] <= summ && summ <= input[1] {
			fmt.Println(summ)
			os.Exit(0)
		} else if input[0] >= summ {
			fmt.Println(input[0])
			os.Exit(0)
		}
	}
	fmt.Println("-1")
}

package main

import (
	"fmt"
)

func readArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a []int
	m int
	l, r []int
)

func read() {
	fmt.Scan(&n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	r = make([]int, m)
	l = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&l[i], &r[i])
	}
}

func main() {
	read()
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	for i := 0; i < m; i++ {
		if sum <= r[i] {
			fmt.Println(sum)
			return
		}
	}
	fmt.Println(-1)
}

package main

import (
	"fmt"
)

func readArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a []int
	m int
	l, r []int
)

func read() {
	fmt.Scan(&n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	r = make([]int, m)
	l = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&l[i], &r[i])
	}
}

func main() {
	read()
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	for i := 0; i < m; i++ {
		if (sum >= l[i] && sum <= r[i]) || sum < l[i] {
			fmt.Println(sum)
			return
		}
	}
	fmt.Println(-1)
}

package main

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

func check(a []int, t int) bool {
	fmt.Println(a)
	tmp := a[t]
	sort.Ints(a)
	fmt.Println(a)
	if tmp == a[t] {
		return true
	}
	return false
}

func main() {
	var n, summ int
	var input [2]int
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	//n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	line, _ = reader.ReadString('\n')
	for _, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		tmp, _ := strconv.Atoi(j)
		summ += tmp
	}
	line, _ = reader.ReadString('\n')
	n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	for i := 0; i < n; i++ {
		line, _ = reader.ReadString('\n')
		for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
			input[i], _ = strconv.Atoi(j)
		}
		if input[0] <= summ && summ <= input[1] {
			fmt.Println(summ)
			os.Exit(0)
		}
	}
	fmt.Println("-1")
}

package main

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

func check(a []int, t int) bool {
	fmt.Println(a)
	tmp := a[t]
	sort.Ints(a)
	fmt.Println(a)
	if tmp == a[t] {
		return true
	}
	return false
}

func main() {
	var n, summ int
	var input [2]int
	var line string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	//n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	line, _ = reader.ReadString('\n')
	for _, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
		tmp, _ := strconv.Atoi(j)
		summ += tmp
	}
	line, _ = reader.ReadString('\n')
	n, _ = strconv.Atoi(strings.TrimRight(line, "\n\r\t "))
	for i := 0; i < n; i++ {
		line, _ = reader.ReadString('\n')
		for i, j := range strings.Split(strings.TrimRight(line, "\n\r\t "), " ") {
			input[i], _ = strconv.Atoi(j)
		}
		if input[0] <= summ && summ <= input[1] {
			fmt.Println(summ)
			os.Exit(0)
		} else if input[0] >= summ {
			fmt.Println(summ)
			os.Exit(0)
		}
	}
	fmt.Println("-1")
}

package main

import (
	"fmt"
)

func readArr(n int) []int{
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	return arr
}

var (
	n int
	a []int
	m int
	l, r []int
)

func read() {
	fmt.Scan(&n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	r = make([]int, m)
	l = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&l[i], &r[i])
	}
}

func main() {
	read()
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	for i := 0; i < m; i++ {
		if sum >= l[i] && sum <= r[i] {
			fmt.Println(sum)
			return
		}
	}
	fmt.Println(-1)
}


You are given a positive decimal number x.Your task is to convert it to the "simple exponential notation".Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b.

The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.

Print the only line — the "simple exponential notation" of the given number x.

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	// "sort"
	"strings"
)

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	log.SetOutput(ioutil.Discard)
	// log.SetOutput(os.Stderr)

	var s string

	fmt.Fscan(reader, &s)
	s = strings.TrimLeft(s, "0")
	dotIndex := strings.Index(s, ".")
	a := ""
	exp := 0

	// println(s, dotIndex)
	if dotIndex == 0 {
		i := 1

		for i < len(s) && s[i] == '0' {
			i++
		}

		a = s[i : i+1]
		s = s[i+1:]
		exp = -i
	} else {
		a = s[:1]

		if dotIndex == -1 {
			exp = len(s) - 1
			s = s[1:]
		} else {
			s = s[1:dotIndex] + s[dotIndex+1:]
			exp = dotIndex - 1
		}
	}

	print(a)

	s = strings.TrimRight(s, "0")
	if len(s) > 0 {
		print(".", s)
	}

	if exp != 0 {
		print("E", exp)
	}

	println()
}

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

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

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF691C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	s := ""
	Fscan(in, &s)
	if !Contains(s, ".") {
		s += "."
	}
	s = Trim(s, "0")
	o := Index(s, ".")
	i := IndexAny(s, "123456789")
	e := o - i
	if e > 0 {
		e--
	}
	s = Trim(s[:o]+s[o+1:], "0")
	if len(s) > 1 {
		s = s[:1] + "." + s[1:]
	}
	Fprint(out, s)
	if e != 0 {
		Fprint(out, "E", e)
	}
}

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


Alice and Bob are playing a game. Initially, they are given a non-empty string $$$s$$$, consisting of lowercase Latin letters. The length of the string is even. Each player also has a string of their own, initially empty.Alice starts, then they alternate moves. In one move, a player takes either the first or the last letter of the string $$$s$$$, removes it from $$$s$$$ and prepends (adds to the beginning) it to their own string.The game ends when the string $$$s$$$ becomes empty. The winner is the player with a lexicographically smaller string. If the players' strings are equal, then it's a draw.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if there exists such position $$$i$$$ that $$$a_j = b_j$$$ for all $$$j < i$$$ and $$$a_i < b_i$$$.What is the result of the game if both players play optimally (e. g. both players try to win; if they can't, then try to draw)?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Each testcase consists of a single line — a non-empty string $$$s$$$, consisting of lowercase Latin letters. The length of the string $$$s$$$ is even. The total length of the strings over all testcases doesn't exceed $$$2000$$$.

For each testcase, print the result of the game if both players play optimally. If Alice wins, print "Alice". If Bob wins, print "Bob". If it's a draw, print "Draw".

NoteOne of the possible games Alice and Bob can play in the first testcase:   Alice picks the first letter in $$$s$$$: $$$s=$$$"orces", $$$a=$$$"f", $$$b=$$$"";  Bob picks the last letter in $$$s$$$: $$$s=$$$"orce", $$$a=$$$"f", $$$b=$$$"s";  Alice picks the last letter in $$$s$$$: $$$s=$$$"orc", $$$a=$$$"ef", $$$b=$$$"s";  Bob picks the first letter in $$$s$$$: $$$s=$$$"rc", $$$a=$$$"ef", $$$b=$$$"os";  Alice picks the last letter in $$$s$$$: $$$s=$$$"r", $$$a=$$$"cef", $$$b=$$$"os";  Bob picks the remaining letter in $$$s$$$: $$$s=$$$"", $$$a=$$$"cef", $$$b=$$$"ros". Alice wins because "cef" < "ros". Neither of the players follows any strategy in this particular example game, so it doesn't show that Alice wins if both play optimally.

package main

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

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

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

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

func (in *R) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}
func NewR(r *bufio.Reader) *R {
	return &R{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}
func (in *R) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func main() {
	CF1728D()
}
func CF1728D() {
	r := NewR(bufio.NewReader(os.Stdin))
	t := r.NextInt()
	for t > 0 {
		t--
		s := r.NextString()
		i, j := 0, len(s)-1
		res := "Draw"
		for i < j {
			if s[i] != s[j] {
				res = "Alice"
				break
			}
			i++
			j--
		}
		if res == "Alice" {
			for ; i < j; i += 2 {
				if s[i] != s[i+1] {
					break
				}
			}
			if i > j {
				res = "Draw"
			}
		}
		fmt.Println(res)
	}
}
func CF1728C() {
	r := NewR(bufio.NewReader(os.Stdin))
	f := func(x int) int {
		if x > 99999999 {
			return 9
		} else if x > 9999999 {
			return 8
		} else if x > 999999 {
			return 7
		} else if x > 99999 {
			return 6
		} else if x > 9999 {
			return 5
		} else if x > 999 {
			return 4
		} else if x > 99 {
			return 3
		} else if x > 9 {
			return 2
		} else {
			return x
		}
	}
	t := r.NextInt()
	for t > 0 {
		t--
		n := r.NextInt()
		am := make(map[int]int, n)
		bm := make(map[int]int, n)
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			am[tmp]++
		}
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			if v, ok := am[tmp]; ok {
				if v > 0 {
					am[tmp]--
					if am[tmp] == 0 {
						delete(am, tmp)
					}
					continue
				}
			}
			bm[tmp]++
		}
		res := 0
		for k, v := range am {
			if k > 9 {
				delete(am, k)
				res += v
				k = f(k)
				am[k] += v
			}
			if vb, ok := bm[k]; ok {
				if v < vb {
					delete(am, k)
					bm[k] -= v
				} else if v > vb {
					delete(bm, k)
					am[k] -= vb
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range bm {
			if k > 9 {
				delete(bm, k)
				res += v
				k = f(k)
				bm[k] += v
			}
			if va, ok := am[k]; ok {
				if v < va {
					delete(bm, k)
					am[k] -= v
				} else if v > va {
					delete(am, k)
					bm[k] -= va
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

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

package main

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

var s string

var dp [2005][2005]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for cs := 0; cs < t; cs++ {
		fmt.Fscan(in, &s)
		n := len(s)
		for i := 1; i < n; i++ {
			if s[i] == s[i-1] {
				dp[i-1][i] = 0
			} else {
				dp[i-1][i] = 1
			}
		}
		for d := 2; d < n; d++ {
			for l := 0; l+d < n; l++ {
				r := l + d
				if d%2 == 0 {
					dp[l][r] = 0
					if dp[l+1][r] == -1 || dp[l][r-1] == -1 {
						dp[l][r] = 0x3f3f3f3f
					}
					if dp[l+1][r] == 0 && dp[l][r] < int('z')+1-int(s[l]) {
						dp[l][r] = int('z') + 1 - int(s[l])
					}
					if dp[l][r-1] == 0 && dp[l][r] < int('z')+1-int(s[r]) {
						dp[l][r] = int('z') + 1 - int(s[r])
					}
				} else {
					dp[l][r] = -1
					tmp := int('z') + 1 - int(s[l])
					if tmp > dp[l+1][r] {
						dp[l][r] = 1
					}
					if tmp == dp[l+1][r] {
						dp[l][r] = 0
					}
					tmp = int('z') + 1 - int(s[r])
					if tmp > dp[l][r-1] {
						dp[l][r] = 1
					}
					if tmp == dp[l][r-1] && dp[l][r] == -1 {
						dp[l][r] = 0
					}
				}
			}
		}
		if dp[0][n-1] == -1 {
			fmt.Fprintln(out, "Bob")
		} else if dp[0][n-1] == 0 {
			fmt.Fprintln(out, "Draw")
		} else if dp[0][n-1] == 1 {
			fmt.Fprintln(out, "Alice")
		}
	}
}

package main

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

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

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

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

func (in *R) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}
func NewR(r *bufio.Reader) *R {
	return &R{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}
func (in *R) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func main() {
	CF1728D()
}
func CF1728D() {
	r := NewR(bufio.NewReader(os.Stdin))
	t := r.NextInt()
	for t > 0 {
		t--
		s := r.NextString()
		i, j := 0, len(s)-1
		res := "Draw"
		for i < j {
			if s[i] != s[j] {
				res = "Alice"
				break
			}
			i++
			j--
		}
		if res == "Alice" {
			draw := true
			for i := 0; i < len(s); i += 2 {
				if s[i] != s[i+1] {
					res = "Alice"
					draw = false
					break
				}
			}
			if draw {
				res = "Draw"
			}
		}
		fmt.Println(res)
	}
}
func CF1728C() {
	r := NewR(bufio.NewReader(os.Stdin))
	f := func(x int) int {
		if x > 99999999 {
			return 9
		} else if x > 9999999 {
			return 8
		} else if x > 999999 {
			return 7
		} else if x > 99999 {
			return 6
		} else if x > 9999 {
			return 5
		} else if x > 999 {
			return 4
		} else if x > 99 {
			return 3
		} else if x > 9 {
			return 2
		} else {
			return x
		}
	}
	t := r.NextInt()
	for t > 0 {
		t--
		n := r.NextInt()
		am := make(map[int]int, n)
		bm := make(map[int]int, n)
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			am[tmp]++
		}
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			if v, ok := am[tmp]; ok {
				if v > 0 {
					am[tmp]--
					if am[tmp] == 0 {
						delete(am, tmp)
					}
					continue
				}
			}
			bm[tmp]++
		}
		res := 0
		for k, v := range am {
			if k > 9 {
				delete(am, k)
				res += v
				k = f(k)
				am[k] += v
			}
			if vb, ok := bm[k]; ok {
				if v < vb {
					delete(am, k)
					bm[k] -= v
				} else if v > vb {
					delete(bm, k)
					am[k] -= vb
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range bm {
			if k > 9 {
				delete(bm, k)
				res += v
				k = f(k)
				bm[k] += v
			}
			if va, ok := am[k]; ok {
				if v < va {
					delete(bm, k)
					am[k] -= v
				} else if v > va {
					delete(am, k)
					bm[k] -= va
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

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

package main

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

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

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

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

func (in *R) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}
func NewR(r *bufio.Reader) *R {
	return &R{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}
func (in *R) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

func main() {
	CF1728D()
}
func CF1728D() {
	r := NewR(bufio.NewReader(os.Stdin))
	t := r.NextInt()
	for t > 0 {
		t--
		s := r.NextString()
		i, j := 0, len(s)-1
		res := "Draw"
		for i < j {
			if s[i] != s[j] {
				res = "Alice"
				break
			}
			i++
			j--
		}
		fmt.Println(res)
	}
}
func CF1728C() {
	r := NewR(bufio.NewReader(os.Stdin))
	f := func(x int) int {
		if x > 99999999 {
			return 9
		} else if x > 9999999 {
			return 8
		} else if x > 999999 {
			return 7
		} else if x > 99999 {
			return 6
		} else if x > 9999 {
			return 5
		} else if x > 999 {
			return 4
		} else if x > 99 {
			return 3
		} else if x > 9 {
			return 2
		} else {
			return x
		}
	}
	t := r.NextInt()
	for t > 0 {
		t--
		n := r.NextInt()
		am := make(map[int]int, n)
		bm := make(map[int]int, n)
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			am[tmp]++
		}
		for i := 0; i < n; i++ {
			tmp := r.NextInt()
			if v, ok := am[tmp]; ok {
				if v > 0 {
					am[tmp]--
					if am[tmp] == 0 {
						delete(am, tmp)
					}
					continue
				}
			}
			bm[tmp]++
		}
		res := 0
		for k, v := range am {
			if k > 9 {
				delete(am, k)
				res += v
				k = f(k)
				am[k] += v
			}
			if vb, ok := bm[k]; ok {
				if v < vb {
					delete(am, k)
					bm[k] -= v
				} else if v > vb {
					delete(bm, k)
					am[k] -= vb
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

		for k, v := range bm {
			if k > 9 {
				delete(bm, k)
				res += v
				k = f(k)
				bm[k] += v
			}
			if va, ok := am[k]; ok {
				if v < va {
					delete(bm, k)
					am[k] -= v
				} else if v > va {
					delete(am, k)
					bm[k] -= va
				} else {
					delete(am, k)
					delete(bm, k)
				}
			}
		}

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

package main

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

var s string

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for cs := 0; cs < t; cs++ {
		fmt.Fscan(in, &s)
		l := len(s)
		for {
			flag := false
			for i := 1; i < l; i++ {
				if s[i] == s[i-1] {
					s = s[:i-1] + s[i+1:]
					flag = true
					l -= 2
					break
				}
			}
			if !flag {
				break
			}
		}
		if l > 0 {
			fmt.Fprintln(out, "Alice")
		} else {
			fmt.Fprintln(out, "Draw")
		}
	}
}


A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.Help the coach and divide the teams the way he wants.

The first line of the input contains integers n and m (3 ≤ n ≤ 48, . Then follow m lines, each contains a pair of integers ai, bi (1 ≤ ai < bi ≤ n) — the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once.

If the required division into teams doesn't exist, print number -1. Otherwise, print  lines. In each line print three integers xi, yi, zi (1 ≤ xi, yi, zi ≤ n) — the i-th team.  If there are multiple answers, you are allowed to print any of them.

package main
import "fmt"

func main() {
	var nn, mm, aa, bb, x, notice int
	var tim[16][4]int
	var y[49]int

	fmt.Scan(&nn, &mm)
	x=-1
	for i:=0; i<49; i++ {
		y[i]=-1
	}

	for i:=0; i<mm; i++ {
		fmt.Scan(&aa, &bb)
		if y[aa]==-1 && y[bb]==-1 {
			x++
			tim[x][0]=2
			tim[x][1]=aa
			tim[x][2]=bb
			y[aa]=x
			y[bb]=x
		} else if y[aa]!=-1 {
			if tim[y[aa]][0]==2 {
					if tim[y[aa]][1]!=bb && tim[y[aa]][2]!=bb {
						tim[y[aa]][0]=3
						tim[y[aa]][3]=bb
						y[bb]=y[aa]
					}
			} else if tim[y[aa]][0]==3 {
					if tim[y[aa]][1]!=bb && tim[y[aa]][2]!=bb && tim[y[aa]][3]!=bb {
						fmt.Println("-1")
						return
					}
			}
		} else if y[bb]!=-1 {
				if tim[y[bb]][0]==2 {
					if tim[y[bb]][1]!=aa && tim[y[bb]][2]!=aa {
						tim[y[bb]][0]=3
						tim[y[bb]][3]=bb
						y[aa]=y[bb]
					}
				} else if tim[y[bb]][0]==3 {
						if tim[y[bb]][1]!=aa && tim[y[bb]][2]!=aa && tim[y[bb]][3]!=aa {
							fmt.Println("-1")
							return
						}
				}
		}
		if x+1 > int(nn/3) {
				fmt.Println("-1")
				return
		}
	}

	x=0
	for i:=1; i<nn+1; i++ {
		if y[i]==-1 {
			notice=0
			for notice==0 {
				if tim[x][0]<3 {
					tim[x][0]+=1
					tim[x][tim[x][0]]=i
					notice=1
				} else {
					x+=1
				}
			}
		}
	}

	for i:=0; i<int(nn/3); i++ {
		fmt.Println(tim[i][1], tim[i][2], tim[i][3])
	}
}

// 300B
package main

import (
	"fmt"
)

func main() {
	var fa, o [50]int
	var n,m,a,b,tt int
	fmt.Scan(&n,&m)
	for i:=0;i<m;i++ {
		fmt.Scan(&a,&b)
		if o[a] != 0{
			o[b]=o[a]
		}
		if o[b] != 0 {
			o[a]=o[b]
		} else {
			tt++
			o[a]=tt
			o[b]=tt
		}
	}
	if tt>n/3 {
		fmt.Println(-1)
		return
	}
	for i:=1;i<=n;i++ {
		fa[o[i]]++
	}
	for i:=1;i<=n/3;i++ {
		if fa[i]>3 {
			fmt.Println(-1)
			return
		}
	}
	for i:=1;i<=n;i++ {
		if o[i]==0	{
			for j:=1;j<=n/3;j++	{
				if fa[j]<3 {
					o[i]=j
					fa[j]++
					break
				}
			}
		}
	}

	if m==0	{
		for i:=1;i<=n;i+=3 {
			fmt.Printf("%d %d %d\n",i,i+1,i+2)
		return
		}
	}
    for i:=1;i<=n/3;i++	{
		for j:=1;j<=n;j++ {
			if o[j]==i{
				fmt.Printf("%d ",j)
			}
		}
		fmt.Println()
	}
	return
}