package main

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

var N int64

const MOD int64 = 1000000007

var v []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &N)

		a, b := solve()

		fmt.Println(a, b)
	}
}

func solve() (int64, int64) {
	//1
	if N == 0 {
		return -1, 1
	}

	if N > 0 {
		return -N + 1, N
	}

	if N < 0 {
		return -N, N - 1
	}

	return 0 , 0
}

package main
import (
	"bufio"
	"fmt"
	"io"
	"os"
)
func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int64
	fmt.Fscan(input, &t)
	for t > 0 {
		var n int64
		fmt.Fscan(input, &n)
		fmt.Println(-n+1, n)
		t--
	}

}

package main

import (
	"fmt"
)

func solve(){
	var n int64
	fmt.Scanf("%d\n", &n)
	fmt.Printf("%d %d\n", -(n-1), n)
}

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

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 uint64
		fmt.Fscanf(r, "%d\n", &n)

		if n-1 == 0 {
			fmt.Println(0, n)
		} else {
			fmt.Println(fmt.Sprintf("-%d", n-1), n)
		}
	}
}

package main
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 x int
		fmt.Fscan(in,&x)
		fmt.Fprintln(out,(x-1)*-1,x)
	}
}

package main

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

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

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

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

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

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

/**
TO SEND
Run solve the problem CF1594A
Date: 9/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1594/A
Problem: CF1594A
**/
func (in *CF1594A) Run() {
	for t := in.NextInt64(); t > 0; t-- {
		n := in.NextInt64()
		fmt.Println(-(n - 1), n)
	}
}

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

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

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-- {
		n := parseInt(getString(reader))
		writer.WriteString(fmt.Sprintln(-(n - 1), n))
	}
	writer.Flush()
}

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

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
}

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 int64
		fmt.Fscan(in, &n)
		fmt.Fprintf(out, "%d %d\n", (n-1)*-1, n)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		p := int64(0)
		fmt.Fscan(f, &p)
		fmt.Fprintln(w, -(p - 1), p)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"fmt"
)
func min(a,b int64) int64 {
	if a>b{
		return b
	}
	return a
}
func main() {
	var t,l,r,n,x int64
	fmt.Scan(&t)
	for t>0 {
		t--
		fmt.Scan(&n)
		x=2
		for n%2==0{
			n=n/2
			x=x*2
		}
		r=(n+x-1)/2
		l=min(n-r,x-r)
		fmt.Println(l,r)
	}
}

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 _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	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 _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int64()
		printf("%d %d\n", -n+1, n)
	}
}

package main

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

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

	var t int
	var n int64
	fmt.Fscanf(in, "%d\n", &t)
	for i:= 0;i < t;i++{
		fmt.Fscanf(in, "%d\n", &n)
		if n == 0{
			fmt.Printf("-1 1\n")
		}else {
			fmt.Printf("%v %v\n", 1-n, n)
		}
	}

}

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int64
		fmt.Scanf("%d\n", &n)
		fmt.Printf("%d %d\n", 1-n, n)
	}
}

package main
import "fmt"

func main(){
	var t int
	fmt.Scanf("%d\n",&t)
	for j:=0; j < t; j++ {
	    var n int64
	    fmt.Scanf("%d\n",&n)
	    fmt.Printf("%d %d\n",-n + 1, n)
	}
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scanf("%d\n", &t)

	for t > 0 {

		var n int64
		fmt.Scanf("%d\n", &n)
		solve(n)
		t--
	}
}

func solve(n int64) {
	if n == 1 {
		fmt.Println("0 1")
		return
	}
	if n == 0 {
		fmt.Println("0 0")
		return
	}
	if n < 0 {
		fmt.Println(n, (n+1)*-1)
		return
	}
	fmt.Println((n-1)*-1, n)

}

package main

import "fmt"

func main() {
	t := 0

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b int64

		fmt.Scan(&a)
		b = 0 - a + 1
		fmt.Print(b)
		fmt.Print(" ")
		fmt.Print(a, "\n")
	}
}

package main

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

// 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
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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 int64

		fmt.Fscan(input, &n)

		if n == 0 {
			fmt.Println(-1)
			fmt.Println(1)

		}
		if n > 0 {
			fmt.Println(1 - n)
			fmt.Println(n)

		}

		if n < 0 {
			fmt.Println(-1 - n)
			fmt.Println(n)

		}
	}

}

package main

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

// 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
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

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 int64

		fmt.Fscan(input, &n)

		if n%2 == 1 {
			q := n / 2

			fmt.Println(q)
			fmt.Println(q + 1)

		} else {
			e := 2 * n
			m := 2 * n
			p := int64(1)
			for m%2 == 0 {
				if m%2 == 1 {
					break
				} else {
					m = m / 2
					p = p * 2
				}
			}

			tak := e / p

			w := (tak - p + 1) / 2

			fmt.Println(w)
			fmt.Println(w + p - 1)

		}

	}

}

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {

		var s int64
		fmt.Scan(&s)
		fmt.Println(-(s - 1), s)
	}
}

package main

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

func readInt() (int, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	_, err := fmt.Fscan(reader, &n)
	return n, err
}

func readInt64() (int64, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int64
	_, err := fmt.Fscan(reader, &n)
	return n, err
}

func main() {
	t, _ := readInt()
	for ; t > 0; t-- {
		n, _ := readInt64()
		fmt.Printf("%d %d\n", 1-n, n)
	}
}

package main

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

func readInt() (int, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	_, err := fmt.Fscan(reader, &n)
	return n, err
}

func readInt64() (int64, error) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	_, err := fmt.Fscan(reader, &n)
	return int64(n), err
}

func main() {
	t, _ := readInt()
	for ; t > 0; t-- {
		n, _ := readInt64()
		fmt.Printf("%d %d\n", 1-n, n)
	}
}

package main

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

func readInt() int {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	number, _ := strconv.ParseInt(string(text[:len(text)-1]), 10, 0)
	return int(number)
}

func readInt64() int64 {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	number, _ := strconv.ParseInt(string(text[:len(text)-1]), 10, 0)
	return number
}

func main() {
	t := readInt()
	for ; t > 0; t-- {
		n := readInt64()
		fmt.Printf("%d %d\n", 1-n, n)
	}
}

package main

import "fmt"

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

package main
import "fmt"

func main(){
	var t int
	fmt.Scanf("%d",&t)
	for i:=0; i < t; i++ {
	    var n int64
	    fmt.Scanf("%d",&n)
	    for i:=int64(2);  ; i++ {
	        var x int64 = (i*(i+1))/2
	        if (n - x) % i == 0 {
	            fmt.Printf("%d %d\n", ((n - x) / i) + 1, ((n - x) / i) + i)
	            break
	        }
	    }
	}
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scanf("%d", &t)

	for t >= 0 {

		var n int64
		fmt.Scanf("%d\n", &n)
		solve(n)
		t--
	}
}

func solve(n int64) {
	if n == 1 {
		fmt.Println("0 1")
		return
	}
	if n < 0 {
		fmt.Println(n, (n+1)*-1)
		return
	}
	fmt.Println((n-1)*-1, n)

}

package main

import "fmt"

func main() {
	var t int

	fmt.Scanf("%d", &t)

	for t >= 0 {

		var n int64
		fmt.Scanf("%d\n", &n)
		solve(n)
		t--
	}
}

func solve(n int64) {
	if n == 1 {
		fmt.Println("0 1")
		return
	}
	if n == 0 {
		fmt.Println("0 0")
		return
	}
	if n < 0 {
		fmt.Println(n, (n+1)*-1)
		return
	}
	fmt.Println((n-1)*-1, n)

}

package main

import "fmt"

func main() {
	var t int

	fmt.Scanf("%d", &t)

	for t >= 0 {

		var n int
		fmt.Scanf("%d\n", &n)
		solve(n)
		t--
	}
}

func solve(n int) {
	if n == 1 {
		fmt.Println("0 1")
		return
	}
	if n == 0 {
		fmt.Println("0 0")
		return
	}
	if n < 0 {
		fmt.Println(n, (n+1)*-1)
		return
	}
	fmt.Println((n-1)*-1, n)

}

package main

import "fmt"

func main() {
	t := 0

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b int64

		fmt.Scan(&a)
		b = 0 - a + 1
		fmt.Print(b)
		fmt.Print(" ")
		fmt.Print(a)
	}
}

package main

import "fmt"

func main() {
	t := 0

	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b int64

		fmt.Scan(&a)
		b = 0 - 1 - a
		fmt.Print(b)
		fmt.Print(" ")
		fmt.Print(a)
	}
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {

		var s int
		fmt.Scan(&s)
		fmt.Println(-(s - 1), s)
	}
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {

		var s string
		fmt.Scan(&s)
		fmt.Println("0", s)
	}
}

package main

import (
	"fmt"
)
func main() {
	var t int64
	fmt.Scanf("%v", &t)
	for t > 0 {
		var n int64
		fmt.Scanf("%v", &n)
		fmt.Println(-n+1, n)
		t--
	}

}

package main

import (
	"fmt"
)

func solve(){
	var n int
	fmt.Scanf("%d\n", &n)
	fmt.Printf("%d %d\n", -(n-1), n)
}

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

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 s string
		fmt.Fscanf(r, "%s\n", &s)

		c := map[byte]int{}
		for i := 0; i < len(s); i++ {
			c[s[i]]++
		}

		if c['>'] != 0 && c['<'] != 0 {
			fmt.Println("?")
		} else if c['>'] != 0 {
			fmt.Println(">")
		} else if c['<'] != 0 {
			fmt.Println("<")
		} else {
			fmt.Println("=")
		}
	}
}


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

type A struct {
	a int64
	b int64
	c int64
}

var ans []A

func init() {
	for a := int64(1); a < 1e9; a++ {
		aa := a * a
		if aa&1 == 0 {
			continue
		}
		b := aa / 2
		c := b + 1
		if c > 1e9 {
			break
		}
		ans = append(ans, A{a, b, c})
	}
}

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

func sol(n int64) int64 {
	l := 0
	r := len(ans)-1
	for l < r {
		m := (l + r) / 2
		if ans[m].c <= n {
			l = m + 1
		} else {
			r = m - 1
		}
	}
	m := (l + r) / 2
	if ans[m].c > n {
		m--
	}
	return int64(m)
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

//const MAX_N = 1000000007
//
//var cc []int
//
//func init() {
//	// c = b + 1
//	// a * a = 2 *b + 1
//
//	for a := 3; a <= (MAX_N*2)/a; a += 2 {
//		x := a * a
//		if x%2 == 1 {
//			b := (x - 1) / 2
//			c := b + 1
//			if c < MAX_N && right(a, b, c) {
//				cc = append(cc, c)
//			}
//		}
//	}
//	sort.Ints(cc)
//}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	if n < 5 {
		return 0
	}
	x := int(math.Sqrt(float64(2*n) - 1))

	if x*x < 2*n-1 {
		if (x+1)*(x+1) == 2*n-1 {
			x++
		}
	}

	if x%2 == 0 {
		x--
	}

	return (x+1)/2 - 1
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

const MAX_N = 1000000007

var cc []int

func init() {
	// c = b + 1
	// a * a = 2 *b + 1

	for a := 3; a <= (MAX_N*2)/a; a += 2 {
		x := a * a
		if x%2 == 1 {
			b := (x - 1) / 2
			c := b + 1
			if c < MAX_N && right(a, b, c) {
				cc = append(cc, c)
			}
		}
	}
	sort.Ints(cc)
}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	i := sort.SearchInts(cc, n)
	if i < len(cc) && cc[i] == n {
		i++
	}
	return i
}

package main

import (
	"fmt"
)

func sqrt(n int) int {
	l := 0
	r := n + 1

	for r-l > 1 {
		mid := (r + l) / 2
		if int64(mid) * int64(mid) <= int64(n) {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

func main() {

	var t int
	fmt.Scanf("%d\n", &t)

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

		fmt.Println((sqrt(2 * n - 1) - 1) / 2)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	a := []int{}
	for i := 1; 2*i*(i+1)+1 < 1e9; i++ {
		a = append(a, 2*i*(i+1)+1)
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, sort.SearchInts(a, n+1))
	}
}

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

package main

import (
	"fmt"
	"math"
)

func get_ans(n1 int64) int64 {
	tmp1 := int64(math.Sqrt(float64((2 * n1) - 1)))
	res1 := (tmp1 - 1) / 2
	return res1
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := int64(0)
		fmt.Scan(&n)
		fmt.Println(get_ans(n))
	}
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)

	for oi := 0; oi < k; oi++ {

		ln, _ := Readln(reader)
		num, _ := strconv.Atoi(ln)
		mxcandidate := int(math.Sqrt(float64(2*num)))
		//cn := make(map[int]int)
		res:=0
		for i := 3; i <= mxcandidate; i+=2 {

			//c:= (i * i + 1) / 2
			res +=1
			//res += num/c

		}
		fmt.Println(res)

	}

}

package main

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

const maxn = 1e9

type query struct {
	idx int
	val int64
	ans int64
}

func solveD(queries []query) {
	sort.Slice(queries, func(i, j int) bool { return queries[i].val < queries[j].val })

	bs := func(c int64) int {
		l, r := -1, len(queries)
		for r-l > 1 {
			m := l + (r-l)/2
			if c <= queries[m].val {
				r = m
			} else {
				l = m
			}
		}
		return r
	}

	ans := make([]int64, len(queries))
	for a := int64(2); a <= maxn; a++ {
		aSquared := a * a
		if (aSquared-1)%2 == 1 {
			continue
		}
		b := (aSquared - 1) / 2
		c := b + 1

		pos := bs(c)
		if pos < len(queries) {
			ans[pos]++
		} else {
			break
		}
	}

	for i := 1; i < len(ans); i++ {
		ans[i] += ans[i-1]
	}

	for i := range queries {
		queries[i].ans = ans[i]
	}

	sort.Slice(queries, func(i, j int) bool { return queries[i].idx < queries[j].idx })

	for _, q := range queries {
		printf("%d\n", q.ans)
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)

	queries := make([]query, T)
	for t := 0; t < T; t++ {
		scan(&queries[t].val)
		queries[t].idx = t
	}
	solveD(queries)
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func gcdExt(a, b int) (int, int, int) {
	if b == 0 {
		return 1, 0, a
	}
	y, x, g := gcdExt(b, a%b)
	return x, y - a/b*x, g
}

func sieve() {
	const maxn = 1e7
	var lp [maxn + 1]int64
	var pr []int64

	for i := int64(2); i <= maxn; i++ {
		if lp[i] == 0 {
			lp[i] = i
			pr = append(pr, i)
		}
		for j := 0; j < len(pr) && pr[j] <= lp[i] && i*pr[j] <= maxn; j++ {
			lp[i*pr[j]] = pr[j]
		}
	}
}

package main

import (
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

type bufferedReader struct {
	buf     [4096]byte
	ptr, sz int
	eof     bool
	ended   bool
	in      *os.File
}

func newReader(in *os.File) bufferedReader {
	var tmp [4096]byte
	return bufferedReader{tmp, 0, 0, false, false, in}
}

func (r *bufferedReader) isEof() bool {
	return r.eof
}

func (r *bufferedReader) load() {
	if r.ended {
		r.eof = true
		return
	}
	sz, err := r.in.Read(r.buf[:])
	r.sz = sz
	if sz < 4096 {
		r.ended = true
	}
	if err != nil {
		log.Fatal(err)
	}
	r.ptr = 0
}

func (r *bufferedReader) getChar() byte {
	if r.ptr == r.sz && !r.eof {
		r.load()
	}
	if r.ptr == r.sz || r.eof {
		r.eof = true
		return 0
	}
	r.ptr += 1
	return r.buf[r.ptr-1]
}

func (r *bufferedReader) skipNonIntChars() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if (c >= 48 && c <= 57) || (c == 45) {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) skipWhitespace() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c != ' ' && c != '\n' && c != '\t' && c != '\r' {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) readInt() int {
	r.skipNonIntChars()
	var ans int = 0
	var neg bool = false
	fst := r.getChar()
	if fst == 45 {
		neg = true
	} else {
		ans = int(fst) - 48
	}
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c >= 48 && c <= 57 {
			ans = ans*10 + int(c-48)
		} else {
			r.ptr -= 1
			break
		}
	}
	if neg {
		ans = -ans
	}
	return ans
}

func (r *bufferedReader) readString() string {
	r.skipWhitespace()
	sz := 0
	capacity := 2
	s := make([]byte, 2)
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c == ' ' || c == '\n' || c == '\t' || c == '\r' {
			r.ptr--
			break
		}
		if sz == capacity {
			capacity <<= 1
			s1 := make([]byte, capacity)
			for i := 0; i < sz; i++ {
				s1[i] = s[i]
			}
			s = s1
		}
		s[sz] = c
		sz++
	}
	return string(s[:sz])
}

func main() {
	var in bufferedReader
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}
	if strings.HasSuffix(hostname, "lenovo") {
		file, _ := os.Open("input.txt")
		in = newReader(file)
	} else {
		in = newReader(os.Stdin)
	}
	T := in.readInt()
	bnd := make([]int, 0)
	for i := 1; i*i <= 2100001488; i += 2 {
		a := i
		b := (a*a - 1) / 2
		c := b + 1
		if b > 0 && a < c {
			bnd = append(bnd, c)
		}
	}
	sort.Ints(bnd)
	for t := 0; t < T; t++ {
		n := in.readInt()
		l := 0
		r := len(bnd)
		if bnd[l] > n {
			fmt.Printf("0\n")
			continue
		}
		for r-l > 1 {
			mid := (l + r) >> 1
			if bnd[mid] > n {
				r = mid
			} else {
				l = mid
			}
		}
		fmt.Printf("%d\n", r)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	var cases int
	scanf("%d\n", &cases)
	for i := 0 ; i < cases; i++{
		result := solve()
		printf("%d\n", result)
	}
}

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

	if n <= 4 {
		return 0
	}
	largestSquare := n + n-1
	largestA := int(math.Sqrt(float64(largestSquare)))
	countA := oddAtOrBelow(largestA)
	return countA-1
}

func isEven(n int) bool {
	return n %2 == 0
}

// number of odd numbers BELOW
// 13 -> 6, 14 -> 7
func oddAtOrBelow(n int) int {
	if isEven(n){
		return n/2
	}
	return n/2 + 1
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 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 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
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
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)
		var count int64
		Sqiare := math.Sqrt(float64(2*n - 1))

		SQUAREROOT := int64(Sqiare)
		if SQUAREROOT%2 == 0 {
			count = SQUAREROOT/2 - 1
		} else {
			count = SQUAREROOT / 2
		}
		fmt.Println(count)

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

//const MAX_N = 1000000007
//
//var cc []int
//
//func init() {
//	// c = b + 1
//	// a * a = 2 *b + 1
//
//	for a := 3; a <= (MAX_N*2)/a; a += 2 {
//		x := a * a
//		if x%2 == 1 {
//			b := (x - 1) / 2
//			c := b + 1
//			if c < MAX_N && right(a, b, c) {
//				cc = append(cc, c)
//			}
//		}
//	}
//	sort.Ints(cc)
//}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	if n < 6 {
		return 0
	}
	x := int(math.Sqrt(float64(2*n) - 1))

	if x*x < 2*n-1 {
		if (x+1)*(x+1) == 2*n-1 {
			x++
		}
	}

	if x*x > 2*n-1 {
		x--
	}

	if x%2 == 0 {
		x--
	}

	return (x+1)/2 - 1
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

//const MAX_N = 1000000007
//
//var cc []int
//
//func init() {
//	// c = b + 1
//	// a * a = 2 *b + 1
//
//	for a := 3; a <= (MAX_N*2)/a; a += 2 {
//		x := a * a
//		if x%2 == 1 {
//			b := (x - 1) / 2
//			c := b + 1
//			if c < MAX_N && right(a, b, c) {
//				cc = append(cc, c)
//			}
//		}
//	}
//	sort.Ints(cc)
//}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	if n < 6 {
		return 0
	}
	x := int(math.Sqrt(float64(2*n) + 1))
	if x*x < 2*n+1 {
		if (x+1)*(x+1) == 2*n+1 {
			x++
		}
	}

	return 1 + (x-3)/2
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

//const MAX_N = 1000000007
//
//var cc []int
//
//func init() {
//	// c = b + 1
//	// a * a = 2 *b + 1
//
//	for a := 3; a <= (MAX_N*2)/a; a += 2 {
//		x := a * a
//		if x%2 == 1 {
//			b := (x - 1) / 2
//			c := b + 1
//			if c < MAX_N && right(a, b, c) {
//				cc = append(cc, c)
//			}
//		}
//	}
//	sort.Ints(cc)
//}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	if n < 6 {
		return 0
	}
	x := int(math.Sqrt(float64(2*n) + 1))
	if x*x < 2*n+1 {
		if (x+1)*(x+1) == 2*n+1 {
			x++
		}
	}

	return (x - 1) / 2
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

const MAX_N = 1000000007

var cc []int

func init() {
	// c = b + 1
	// a * a = 2 *b + 1
	for a := 3; a <= MAX_N/a; a += 2 {
		x := a * a
		if x%2 == 1 {
			b := (x - 1) / 2
			c := b + 1
			if c < MAX_N && right(a, b, c) {
				cc = append(cc, c)
			}
		}
	}
	sort.Ints(cc)
}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	i := sort.SearchInts(cc, n)
	if i < len(cc) && cc[i] == n {
		i++
	}
	return i
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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') && 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
}

const MAX_N = 1000000007

var cc []int

func init() {
	// c = b + 1
	// a * a = 2 *b + 1
	for a := 3; a <= MAX_N/a; a += 2 {
		x := a * a
		if x%2 == 1 {
			b := (x - 1) / 2
			c := b + 1
			if c < MAX_N && right(a, b, c) {
				cc = append(cc, c)
			}
		}
	}
	sort.Ints(cc)
}

func right(a, b, c int) bool {
	A, B, C := int64(a), int64(b), int64(c)
	return A*A+B*B == C*C
}

func solve(n int) int {
	i := sort.SearchInts(cc, n)
	return i
}

package main

import (
	"fmt"
)

func sqrt(n int) int {
	l := 0
	r := n + 1

	for r-l > 1 {
		mid := (r + l) / 2
		if int64(mid) * int64(mid) <= int64(n) {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

func main() {

	var t int
	fmt.Scanf("%d", &t)

	for i := 0; i < t; i++  {
		var n int
		fmt.Scanf("%d", &n)

		fmt.Println((sqrt(2 * n - 1) - 1) / 2)
	}
}

package main

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

func sqrt(n int) int {
	l := 0
	r := n + 1

	for r-l > 1 {
		mid := (r + l) / 2
		if int64(mid) * int64(mid) <= int64(n) {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

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

	text, _ := reader.ReadString('\n')
	// convert CRLF to LF
	text = strings.Replace(text, "\n", "", -1)

	t, _ := strconv.Atoi(text)

	for i := 0; i < t; i++  {
		textN, _ := reader.ReadString('\n')
		// convert CRLF to LF
		textN = strings.Replace(textN, "\n", "", -1)

		n, _ := strconv.Atoi(textN)

		fmt.Println((sqrt(2 * n - 1) - 1) / 2)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	a := []int{}
	for i := 1; 2*i*(i+1)+1 < 1e9; i++ {
		a = append(a, 2*i*(i+1)+1)
	}

	var T, n int
	c:=0
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c++

		if c == 302 {
			Fprintln(out, n)
			break
		}
		Fprintln(out, sort.SearchInts(a, n))

	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	a := []int{}
	for i := 1; 2*i*(i+1)+1 < 1e9; i++ {
		a = append(a, 2*i*(i+1)+1)
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, sort.SearchInts(a, n))
	}
}

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

package main

import (
	"fmt"
	"math"
)

func get_ans(n1 int64) int64 {
	tmp1 := int64(math.Sqrt(float64((2 * n1) - 1)))
	res1 := (tmp1 - 3) / 2
	return res1
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := int64(0)
		fmt.Scan(&n)
		fmt.Println(get_ans(n))
	}
}

package main

import (
	"fmt"
	"math"
)

func get_ans(n1 int64) int64 {
	tmp1 := int64(math.Sqrt(float64((2 * n1) + 1)))
	res1 := int64(0)
	if (tmp1 % 2) == 0 {
		res1 = (tmp1 / 2) - 1
	} else {
		res1 = tmp1 / 2
	}
	return res1
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := int64(0)
		fmt.Scan(&n)
		fmt.Println(get_ans(n))
	}
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)

	for oi := 0; oi < k; oi++ {

		ln, _ := Readln(reader)
		num, _ := strconv.Atoi(ln)
		mxcandidate := int(math.Sqrt(float64(2*num))) + 1
		//cn := make(map[int]int)
		res:=0
		for i := 3; i <= mxcandidate; i+=2 {

			c:= (i * i + 1) / 2

			res += num/c

		}
		fmt.Println(res)

	}

}

package main

import (
	"fmt"
	"log"
	"os"
	"sort"
	"strings"
)

type bufferedReader struct {
	buf     [4096]byte
	ptr, sz int
	eof     bool
	ended   bool
	in      *os.File
}

func newReader(in *os.File) bufferedReader {
	var tmp [4096]byte
	return bufferedReader{tmp, 0, 0, false, false, in}
}

func (r *bufferedReader) isEof() bool {
	return r.eof
}

func (r *bufferedReader) load() {
	if r.ended {
		r.eof = true
		return
	}
	sz, err := r.in.Read(r.buf[:])
	r.sz = sz
	if sz < 4096 {
		r.ended = true
	}
	if err != nil {
		log.Fatal(err)
	}
	r.ptr = 0
}

func (r *bufferedReader) getChar() byte {
	if r.ptr == r.sz && !r.eof {
		r.load()
	}
	if r.ptr == r.sz || r.eof {
		r.eof = true
		return 0
	}
	r.ptr += 1
	return r.buf[r.ptr-1]
}

func (r *bufferedReader) skipNonIntChars() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if (c >= 48 && c <= 57) || (c == 45) {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) skipWhitespace() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c != ' ' && c != '\n' && c != '\t' && c != '\r' {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) readInt() int {
	r.skipNonIntChars()
	var ans int = 0
	var neg bool = false
	fst := r.getChar()
	if fst == 45 {
		neg = true
	} else {
		ans = int(fst) - 48
	}
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c >= 48 && c <= 57 {
			ans = ans*10 + int(c-48)
		} else {
			r.ptr -= 1
			break
		}
	}
	if neg {
		ans = -ans
	}
	return ans
}

func (r *bufferedReader) readString() string {
	r.skipWhitespace()
	sz := 0
	capacity := 2
	s := make([]byte, 2)
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c == ' ' || c == '\n' || c == '\t' || c == '\r' {
			r.ptr--
			break
		}
		if sz == capacity {
			capacity <<= 1
			s1 := make([]byte, capacity)
			for i := 0; i < sz; i++ {
				s1[i] = s[i]
			}
			s = s1
		}
		s[sz] = c
		sz++
	}
	return string(s[:sz])
}

func main() {
	var in bufferedReader
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}
	if strings.HasSuffix(hostname, "lenovo") {
		file, _ := os.Open("input.txt")
		in = newReader(file)
	} else {
		in = newReader(os.Stdin)
	}
	T := in.readInt()
	bnd := make([]int, 0)
	for i := 1; i*i <= 1000000000; i += 2 {
		a := i
		b := (a*a - 1) / 2
		c := b + 1
		if b > 0 && a < c {
			bnd = append(bnd, c)
		}
	}
	sort.Ints(bnd)
	for t := 0; t < T; t++ {
		n := in.readInt()
		l := 0
		r := len(bnd)
		if bnd[l] > n {
			fmt.Printf("0\n")
			continue
		}
		for r-l > 1 {
			mid := (l + r) >> 1
			if bnd[mid] > n {
				r = mid
			} else {
				l = mid
			}
		}
		fmt.Printf("%d\n", r)
	}
}


package main

import "fmt"

func ways(n int, a, b string) int64 {
	var s10, s00, one, zero int64
	for i, v := range a {
		bc := b[i]
		if v == '0' {
			zero++
		} else {
			one++
		}
		if v == '0' && bc == '0' {
			s00++
		}
		if v == '1' && bc == '0' {
			s10++
		}
	}
	return s10*(zero-s00) + s00*one
}

func main() {
	var n int
	var a, b string
	fmt.Scanf("%d\n%s\n%s\n", &n, &a, &b)
	fmt.Println(ways(n, a, b))
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func ways(a, b string) int64 {
	var s10, s00, one, zero int64
	for i, v := range a {
		bc := b[i]
		if v == '0' {
			zero++
		} else {
			one++
		}
		if v == '0' && bc == '0' {
			s00++
		}
		if v == '1' && bc == '0' {
			s10++
		}
	}
	return s10*(zero-s00) + s00*one
}

func main() {
	var n int
	var a, b string
	scanf("%d\n%s\n%s\n", &n, &a, &b)
	printf("%d\n", ways(a, b))

	writer.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a,b string
	fmt.Scan(&a,&b)
	var y int
	for _,c := range b {
		if c == '0' {
			y++
		}
	}
	fmt.Println(y*2)
}


package main

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

func main() {

	//stdin, err := os.Open("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

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

	for i := 0; i < q; i++ {
		var n, k int
		r, g, b := make([]int, 0), make([]int, 0), make([]int, 0)
		fmt.Fscanf(reader, "%d %d\n", &n, &k)

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

		for j := 0; j < n; j++ {

			if j%3 == 0 {
				if s[j] == 'R' {
					r = append(r, 0)
				} else {
					r = append(r, 1)
				}

				if s[j] == 'G' {
					g = append(g, 0)
				} else {
					g = append(g, 1)
				}

				if s[j] == 'B' {
					b = append(b, 0)
				} else {
					b = append(b, 1)
				}

			} else if j%3 == 1 {
				if s[j] == 'G' {
					r = append(r, 0)
				} else {
					r = append(r, 1)
				}

				if s[j] == 'B' {
					g = append(g, 0)
				} else {
					g = append(g, 1)
				}

				if s[j] == 'R' {
					b = append(b, 0)
				} else {
					b = append(b, 1)
				}

			} else if j%3 == 2 {
				if s[j] == 'B' {
					r = append(r, 0)
				} else {
					r = append(r, 1)
				}

				if s[j] == 'R' {
					g = append(g, 0)
				} else {
					g = append(g, 1)
				}

				if s[j] == 'G' {
					b = append(b, 0)
				} else {
					b = append(b, 1)
				}
			}
		}

		for j := 1; j < n; j++ {
			r[j] += r[j-1]
			g[j] += g[j-1]
			b[j] += b[j-1]
		}

		var min int = 2e3 + 1
		min = int(math.Min(float64(min), float64(r[k-1])))
		min = int(math.Min(float64(min), float64(g[k-1])))
		min = int(math.Min(float64(min), float64(b[k-1])))
		//fmt.Println(min)
		for j := k; j < n; j++ {
			min = int(math.Min(float64(min), float64(r[j])-float64(r[j-k])))
			min = int(math.Min(float64(min), float64(g[j])-float64(g[j-k])))
			min = int(math.Min(float64(min), float64(b[j])-float64(b[j-k])))
		}

		//fmt.Println(r)
		//fmt.Println(g)
		//fmt.Println(b)

		fmt.Println(min)

	}

	writer.Flush()
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne()
	}
}

func solveOne() {

	n, k := readInt(), readInt()

	arr1 := make([]int, n)
	arr2 := make([]int, n)
	arr3 := make([]int, n)

	s := read()

	for i := 0; i < n; i++ {
		var e1, e2, e3 byte
		switch i % 3 {
		case 0:
			e1, e2, e3 = 'R', 'G', 'B'
		case 1:
			e1, e2, e3 = 'G', 'B', 'R'
		case 2:
			e1, e2, e3 = 'B', 'R', 'G'
		}
		if e1 == s[i] {
			arr1[i] = 1
		}
		if e2 == s[i] {
			arr2[i] = 1
		}
		if e3 == s[i] {
			arr3[i] = 1
		}
	}

	min := check(arr1, k, n)
	cand := check(arr2, k, n)
	if cand < min {
		min = cand
	}
	cand = check(arr3, k, n)
	if cand < min {
		min = cand
	}

	printInt(min)

}

func check(arr []int, k int, n int) int {
	cur := 0
	for i := 0; i < k; i++ {
		cur += arr[i]
	}
	max := cur
	for i := 0; i < n-k; i++ {
		cur += arr[i+k] - arr[i]
		if cur > max {
			max = cur
		}
	}
	return k - max
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

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

	var q int
	rgb := "RGB"
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0;i < q;i ++ {
		var n, k int
		var s string
		fmt.Fscanf(reader, "%d %d\n", &n, &k)
		fmt.Fscanf(reader, "%s\n", &s)
		min := k + 1
		for j := 0;j < 3;j ++ {
			diff := 0
			for left, right := 0,0;right < n;right ++ {
				if s[right] != rgb[(right + j) % 3] {
					diff ++
				}
				if right - left + 1 == k {
					if diff < min {
						min = diff
					}
					if s[left] != rgb[(left + j) % 3] {
						diff --
					}
					left ++
				}
			}
		}
		fmt.Printf("%d\n", min)
	}
}

package main

import (
	"fmt"
)

const (
	MAXN = int(2000 + 7)
)

func Min(x int, y ...int) int {
	minVal := x
	for _, v := range y {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func solve(s string) int {
	toNum := func(x byte) (result int) {
		switch x {
		case 'R':
			result = 0
		case 'G':
			result = 1
		case 'B':
			result = 2
		}
		return
	}

	var dp [MAXN][3] int
	dp[0][0], dp[0][1], dp[0][2] = 1, 1, 1
	dp[0][toNum(s[0])] = 0
	//fmt.Println(dp[0])
	for i:=1;i<len(s);i++{
		for j:=0;j<3;j++{
			if j==toNum(s[i]){
				dp[i][j]=dp[i-1][(j+2)%3]
			}else {
				dp[i][j]=dp[i-1][(j+2)%3]+1
			}
		}
		//fmt.Println(dp[i])
	}
	return Min(dp[len(s)-1][0], dp[len(s)-1][1], dp[len(s)-1][2])
}

func main() {
	var N int
	_, _ = fmt.Scanf("%d\n", &N)
	for test := 1; test <= N; test++ {
		var n, k int
		_, _ = fmt.Scanf("%d %d\n", &n, &k)
		var s string
		_, _ = fmt.Scanf("%s\n", &s)
		ans := n
		for i := 0; i <= n-k; i++ {
			ans = Min(solve(s[i:i+k]), ans)
		}
		fmt.Println(ans)
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1196/problem/D1, https://codeforces.com/contest/1196/problem/D2

package main

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

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

func Solve(n int, k int, s string) int {
	rotations := []string{"RGB", "GBR", "BRG"}
	dp := make([]int, n+1)
	solution := n + 1
	for _, rotation := range rotations {
		wrong := 0
		for i := 0; i < n; i++ {
			if rotation[i%3] != s[i] {
				wrong += 1
			}
			dp[i+1] = wrong
			if i+1 >= k {
				solution = min(solution, dp[i+1]-dp[i+1-k])
			}
		}
	}
	return solution
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n, k int
		fmt.Fscanf(reader, "%d %d\n", &n, &k)
		var s string
		fmt.Fscanf(reader, "%s\n", &s)
		fmt.Fprintf(writer, "%d\n", Solve(n, k, s))
	}
}

package main

import (
	"fmt"
)

const (
	MAXN = int(2000 + 7)
)

func Min(x int, y ...int) int {
	minVal := x
	for _, v := range y {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func solve(s string) int {
	toNum := func(x byte) (result int) {
		switch x {
		case 'R':
			result = 0
		case 'G':
			result = 1
		case 'B':
			result = 2
		}
		return
	}

	var dp [MAXN][3] int
	dp[0][1], dp[0][1], dp[0][2] = 1, 1, 1
	dp[0][toNum(s[0])] = 0

	for id, _ := range s {
		now := toNum(s[id])
		next := (now + 1) % 3
		//fmt.Println(id, next)
		for j := 0; j < 3; j++ {
			dp[id+1][j] = dp[id][(j+2)%3]+1
			if j==next{
				dp[id+1][j]=Min(dp[id+1][j],dp[id][now])
			}
		}
		//fmt.Println(dp[id+1])
	}
	return Min(dp[len(s)][0], dp[len(s)][1], dp[len(s)][2])
}

func main() {
	var N int
	_, _ = fmt.Scanf("%d\n", &N)
	for test := 1; test <= N; test++ {
		var n, k int
		_, _ = fmt.Scanf("%d %d\n", &n, &k)
		var s string
		_, _ = fmt.Scanf("%s\n", &s)
		ans := n
		for i := 0; i <= n-k; i++ {
			ans = Min(solve(s[i:i+k]), ans)
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

const (
	MAXN = int(2000 + 7)
)

func Min(x int, y ...int) int {
	minVal := x
	for _, v := range y {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func solve(s string) int {
	toNum := func(x byte) (result int) {
		switch x {
		case 'R':
			result = 0
		case 'G':
			result = 1
		case 'B':
			result = 2
		}
		return
	}

	var dp [MAXN][3] int
	dp[0][0], dp[0][1], dp[0][2] = 1, 1, 1
	dp[0][toNum(s[0])] = 0

	for id, _ := range s {
		now := toNum(s[id])
		next := (now + 1) % 3
		//fmt.Println(id, next)
		for j := 0; j < 3; j++ {
			dp[id+1][j] = dp[id][(j+2)%3] + 1
			if j == next {
				dp[id+1][j] = Min(dp[id+1][j], dp[id][now])
			}
		}
		//fmt.Println(dp[id+1])
	}
	return Min(dp[len(s)][0], dp[len(s)][1], dp[len(s)][2])
}

func main() {
	var N int
	_, _ = fmt.Scanf("%d\n", &N)
	for test := 1; test <= N; test++ {
		var n, k int
		_, _ = fmt.Scanf("%d %d\n", &n, &k)
		var s string
		_, _ = fmt.Scanf("%s\n", &s)
		ans := n
		for i := 0; i <= n-k; i++ {
			ans = Min(solve(s[i:i+k]), ans)
		}
		fmt.Println(ans)
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1499E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353
	f := func(s []byte) []uint {
		n := len(s)
		df := make([]uint, n)
		df[0] = 1
		for i := 1; i < n; i++ {
			if s[i] != s[i-1] {
				df[i] = df[i-1] + 1
			} else {
				df[i] = 1
			}
		}
		return df
	}

	var s, t []byte
	Fscan(in, &s, &t)
	diffS, diffT := f(s), f(t)
	dp := make([][][2]uint, len(s))
	for i := range dp {
		dp[i] = make([][2]uint, len(t))
	}
	ans := uint(0)
	for i, v := range s {
		for j, w := range t {
			if v != w {
				dp[i][j][0] = diffT[j]
				dp[i][j][1] = diffS[i]
			}
			if i > 0 {
				if v != w {
					dp[i][j][0] = (dp[i][j][0] + dp[i-1][j][1]) % mod
				}
				if v != s[i-1] {
					dp[i][j][0] = (dp[i][j][0] + dp[i-1][j][0]) % mod
				}
			}
			if j > 0 {
				if w != v {
					dp[i][j][1] = (dp[i][j][1] + dp[i][j-1][0]) % mod
				}
				if w != t[j-1] {
					dp[i][j][1] = (dp[i][j][1] + dp[i][j-1][1]) % mod
				}
			}
			ans = (ans + dp[i][j][0] + dp[i][j][1]) % mod
		}
	}
	Fprint(out, ans)
}

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

package main

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

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

	var buf bytes.Buffer

	x, _ := reader.ReadString('\n')
	y, _ := reader.ReadString('\n')

	res := solve(normalize(x), normalize(y))
	buf.WriteString(fmt.Sprintf("%d\n", res))
	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') && 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 normalize(s string) string {
	for i := 0; i < len(s); i++ {
		if s[i] < 'a' || s[i] > 'z' {
			return s[:i]
		}
	}
	return s
}

const MOD = 998244353

func solve(x, y string) int {
	m := len(x)
	n := len(y)
	dp := make([][][][]int64, m+1)
	for i := 0; i <= m; i++ {
		dp[i] = make([][][]int64, n+1)
		for j := 0; j <= n; j++ {
			dp[i][j] = make([][]int64, 2)
			for k := 0; k < 2; k++ {
				dp[i][j][k] = make([]int64, 4)
			}
		}
	}
	var res int64
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			if i < m {
				modAdd(&dp[i+1][j][0][1], 1)
			}
			if j < n {
				modAdd(&dp[i][j+1][1][2], 1)
			}
			for mask := 0; mask < 4; mask++ {
				if 0 < i && i < m && x[i-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][0][mask])
				}
				if i < m && 0 < j && y[j-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][1][mask])
				}

				if 0 < j && j < n && y[j-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][1][mask])
				}

				if 0 < i && j < n && x[i-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][0][mask])
				}
			}
			modAdd(&res, dp[i][j][0][3])
			modAdd(&res, dp[i][j][1][3])
		}
	}

	return int(res)
}

func modAdd(a *int64, b int64) {
	*a += b
	if *a >= MOD {
		*a -= MOD
	}
}

package main

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

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

	var buf bytes.Buffer

	var x, y string
	fmt.Scanf("%s", &x)
	fmt.Scanf("%s", &y)
	res := solve(x, y)
	buf.WriteString(fmt.Sprintf("%d\n", res))
	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') && 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
}

const MOD = 998244353

func solve(x, y string) int {
	m := len(x)
	n := len(y)
	dp := make([][][][]int64, m+1)
	for i := 0; i <= m; i++ {
		dp[i] = make([][][]int64, n+1)
		for j := 0; j <= n; j++ {
			dp[i][j] = make([][]int64, 2)
			for k := 0; k < 2; k++ {
				dp[i][j][k] = make([]int64, 4)
			}
		}
	}
	var res int64
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			if i < m {
				modAdd(&dp[i+1][j][0][1], 1)
			}
			if j < n {
				modAdd(&dp[i][j+1][1][2], 1)
			}
			for mask := 0; mask < 4; mask++ {
				if 0 < i && i < m && x[i-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][0][mask])
				}
				if i < m && 0 < j && y[j-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][1][mask])
				}

				if 0 < j && j < n && y[j-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][1][mask])
				}

				if 0 < i && j < n && x[i-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][0][mask])
				}
			}
			modAdd(&res, dp[i][j][0][3])
			modAdd(&res, dp[i][j][1][3])
		}
	}

	return int(res)
}

func modAdd(a *int64, b int64) {
	*a += b
	if *a >= MOD {
		*a -= MOD
	}
}

package main

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

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

	var buf bytes.Buffer

	x, _ := reader.ReadString('\n')
	y, _ := reader.ReadString('\n')
	x = x[:len(x)-1]
	y = y[:len(y)-1]
	res := solve(x, y)
	buf.WriteString(fmt.Sprintf("%d\n", res))
	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') && 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
}

const MOD = 998244353

func solve(x, y string) int {
	m := len(x)
	n := len(y)
	dp := make([][][][]int64, m+1)
	for i := 0; i <= m; i++ {
		dp[i] = make([][][]int64, n+1)
		for j := 0; j <= n; j++ {
			dp[i][j] = make([][]int64, 2)
			for k := 0; k < 2; k++ {
				dp[i][j][k] = make([]int64, 4)
			}
		}
	}
	var res int64
	for i := 0; i <= m; i++ {
		for j := 0; j <= n; j++ {
			if i < m {
				modAdd(&dp[i+1][j][0][1], 1)
			}
			if j < n {
				modAdd(&dp[i][j+1][1][2], 1)
			}
			for mask := 0; mask < 4; mask++ {
				if 0 < i && i < m && x[i-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][0][mask])
				}
				if i < m && 0 < j && y[j-1] != x[i] {
					modAdd(&dp[i+1][j][0][mask|1], dp[i][j][1][mask])
				}

				if 0 < j && j < n && y[j-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][1][mask])
				}

				if 0 < i && j < n && x[i-1] != y[j] {
					modAdd(&dp[i][j+1][1][mask|2], dp[i][j][0][mask])
				}
			}
			modAdd(&res, dp[i][j][0][3])
			modAdd(&res, dp[i][j][1][3])
		}
	}

	return int(res)
}

func modAdd(a *int64, b int64) {
	*a += b
	if *a >= MOD {
		*a -= MOD
	}
}


package main

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

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

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)

	l := 0
	for i := 0; i < k; i++ {
		bs.Scan()
		m, _ := strconv.Atoi(bs.Text())

		first := 1
		for ; m > 0; m-- {
			bs.Scan()
			a, _ := strconv.Atoi(bs.Text())

			if a == first {
				first++
				l++
			}
		}
	}

	fmt.Println(2*n - k + 1 - 2*l)
}

package main

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

func main() {
        r := bufio.NewReader(os.Stdin)
        ch := 0
        var n, k int
        fmt.Fscanf(r, "%d %d\n", &n, &k)
        for z := 0; z < k; z++ {
                m, x, t := 1, 1, 1
                fmt.Fscanf(r, "%d", &m)
                for ; m > 0; m-- {
                        fmt.Fscanf(r, "%d", &x)
                        if x == t {
                                ch++
                                t++
                        }
                }
                fmt.Fscanf(r, "\n")
        }
        fmt.Printf("%d\n", n-ch+1-k+n-ch)
}

package main

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

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

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

	_, k := nextInt(), nextInt()
	m, ops := 0, 0
	a := make([]int, 100000)

	for ; k > 0; k-- {
		m = nextInt()

		for i := 0; i < m; i++ {
			a[i] = nextInt()
		}

		if a[0] == 1 {
			i := 1

			for i < m && a[i] == a[i-1]+1 {
				i++
			}

			m -= i
			ops += 2
		}

		ops += m*2 - 1
	}

	println(ops - 1)
}

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

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

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

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

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

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

package main

import "fmt"

func main() {
        ch := 0
        var n, k int
        fmt.Scanf("%d%d", &n, &k)
        for z := 0; z < k; z++ {
                m, x, t := 1, 1, 1
                fmt.Scanf("%d", &m)
                for ; m > 0; m-- {
                        fmt.Scanf("%d", &x)
                        if x == t {
                                ch++
                                t++
                        }
                }
        }
        fmt.Printf("%d\n", n-ch+1-k+n-ch)
}

package main

import "fmt"

func main() {
        ch := 0
        var n, k int
        fmt.Scanf("%d%d", &n, &k)
        for z := 0; z < k; z++ {
                m, x, t := 1, 1, 1
                fmt.Scanf("%d", &m)
                for ; m > 0; m-- {
                        fmt.Scanf("%d", &x)
                        if x == t {
                                ch++
                                t++
                        }
                }
        }
        fmt.Printf("%d", n-ch+1-k+n-ch)
}

package main

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

var r = bufio.NewReader(os.Stdin)

func main() {
        ch := 0
        var n, k int
        fmt.Fscanf(r, "%d%d", &n, &k)
        for z := 0; z < k; z++ {
                m, x, t := 1, 1, 1
                fmt.Fscanf(r, "%d", &m)
                for ; m > 0; m-- {
                        fmt.Fscanf(r, "%d", &x)
                        if x == t {
                                ch++
                                t++
                        }
                }
        }
        fmt.Printf("%d\n", n-ch+1-k+n-ch)
}

package main

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

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

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

	_, k := nextInt(), nextInt()
	m, ops := 0, 0
	a := make([]int, 100000)
	ops += k

	for ; k > 0; k-- {
		m = nextInt()

		for i := 0; i < m; i++ {
			a[i] = nextInt()
		}

		for i := 1; i < m; i++ {
			if a[i] != a[i-1]+1 {
				ops += 2
			}
		}
	}

	println(ops - 1)
}

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

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

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

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

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

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


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	hills := make([]int, n+1)

	var pivot int
	for i := 1; i < n; i++ {
		if H[i] > H[pivot] {
			pivot = i
		}
	}

	copy(hills, H[pivot:])
	copy(hills[n-pivot:], H[0:])
	hills[n] = H[pivot]
	//n++

	C := make([]int, n+1)
	R := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		R[i] = i + 1
		for R[i] < n && hills[i] > hills[R[i]] {
			R[i] = R[R[i]]
		}
		if R[i] < n && hills[i] == hills[R[i]] {
			C[i] = C[R[i]] + 1
			R[i] = R[R[i]]
		}
	}

	L := make([]int, n+1)
	for i := 1; i <= n; i++ {
		L[i] = i - 1
		for L[i] > 0 && hills[i] >= hills[L[i]] {
			L[i] = L[L[i]]
		}
	}

	var res int64

	for i := 0; i < n; i++ {
		res += int64(C[i])
		if hills[i] < hills[0] {
			if L[i] == 0 && R[i] == n {
				res++
			} else {
				res += 2
			}
		}
	}

	return res
}

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
}

package main

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

type Node struct {
	value int
	count int64
}

func reverse(a []int) {
	for i := 0; ; i++ {
		j := len(a) - i - 1
		if i >= j {
			return
		}
		a[i], a[j] = a[j], a[i]
	}
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	number := make([]int, 0, 1000000)
	sorted := make([]int, 0, 1000000)
	stack := make([]*Node, 1000000, 1000000)
	var pointer int
	for i := 0; i < n; i++ {
		var hill int
		fmt.Fscanf(reader, "%d ", &hill)
		number = append(number, hill)
		sorted = append(sorted, hill)
	}

	sort.Ints(sorted)
	max := sorted[n-1]
	prev, pos := max, n

	result := int64(0)
	maxPos := 0
	for i := n - 1; i >= 0; i-- {
		if sorted[i] != prev {
			pos = i + 1
			prev = sorted[i]
		}
		inc := n - pos
		if inc >= 2 {
			result += 2
		} else {
			result += int64(inc)
		}
		if number[i] == max {
			maxPos = i
		}
	}
	reverse(number[:maxPos+1])
	reverse(number[maxPos+1:])
	reverse(number)

	for i := 0; i < len(number); i++ {
		for pointer != 0 {
			if stack[pointer-1].value == number[i] {
				stack[pointer-1].count++
				break
			} else if stack[pointer-1].value > number[i] {
				stack[pointer] = &Node{number[i], 1}
				pointer++
				break
			} else {
				count := stack[pointer-1].count
				result = result + (count * (count - 1) / 2)
				pointer--
			}
		}
		if pointer == 0 {
			stack[pointer] = &Node{number[i], 1}
			pointer++
		}
	}

	for pointer != 0 {
		count := stack[pointer-1].count
		result = result + (count * (count - 1) / 2)
		pointer--
	}

	fmt.Printf("%d", result)

}

package main

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

type Node struct {
	value int
	count int64
}

func reverse(a []int) {
	for i := 0; ; i++ {
		j := len(a) - i - 1
		if i >= j {
			return
		}
		a[i], a[j] = a[j], a[i]
	}
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	number := make([]int, 0, 1000000)
	sorted := make([]int, 0, 1000000)
	stack := make([]*Node, 1000000, 1000000)
	var pointer int
	for i := 0; i < n; i++ {
		var hill int
		fmt.Fscanf(reader, "%d ", &hill)
		number = append(number, hill)
		sorted = append(sorted, hill)
	}

	sort.Ints(sorted)
	max := sorted[n-1]
	prev, pos := max, n

	result := int64(0)
	maxPos := 0
	for i := n - 1; i >= 0; i-- {
		if sorted[i] != prev {
			pos = i + 1
			max = sorted[i]
		}
		inc := n - pos
		if inc >= 2 {
			result += 2
		} else {
			result += int64(inc)
		}
		if number[i] == max {
			maxPos = i
		}
	}
	reverse(number[:maxPos])
	reverse(number[maxPos:])
	reverse(number)

	for i := 0; i < len(number); i++ {
		for pointer != 0 {
			if stack[pointer-1].value == number[i] {
				stack[pointer-1].count++
				break
			} else if stack[pointer-1].value > number[i] {
				stack[pointer] = &Node{number[i], 1}
				pointer++
				break
			} else {
				count := stack[pointer-1].count
				result = result + (count * (count - 1) / 2)
				pointer--
			}
		}
		if pointer == 0 {
			stack[pointer] = &Node{number[i], 1}
			pointer++
		}
	}

	for pointer != 0 {
		count := stack[pointer-1].count
		result = result + (count * (count - 1) / 2)
		pointer--
	}

	fmt.Printf("%d", result)

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	if tail-2 > head && HH[stack[tail-1]] == HH[stack[head]] {
		res++
	}

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

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
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	if tail-1 > head && HH[stack[tail-1]] == HH[stack[head]] {
		res++
	}

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

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
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

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
}