package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF  = int64(math.MaxInt64)
	NINF = int64(math.MinInt64)
	MOD  = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		res := sol(n, k, a)
		for _, i := range res {
			printf("%d ", i)
		}
		printf("\n")
	}
}

func sol(n, k int64, a []int64) []int64 {
	maxi := max(a[0], a[1:]...)
	// make everything positive
	for i := range a {
		a[i] = maxi - a[i]
	}
	k--
	maxi = max(a[0], a[1:]...)
	k = k & 1
	if k == 1 {
		for i := range a {
			a[i] = maxi - a[i]
		}
		k--
	}
	if k != 0 {
		panic("k not 0")
	}
	return a
}

package main

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

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

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

func run(args []string, s *bufio.Scanner) error {
	// Want to scan words instead of lines? s.Split(bufio.ScanWords)
	s.Split(bufio.ScanWords)
	s.Scan()

	testCases, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for testCases > 0 && s.Scan() {
		n, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}
		s.Scan()
		//k, err := strconv.Atoi(s.Text())
		k, success := big.NewInt(0).SetString(s.Text(), 10)
		if !success {
			return fmt.Errorf("could not convert to big int")
		}

		var a []int

		for i := 0; i < n && s.Scan(); i++ {
			elem, err := strconv.Atoi(s.Text())
			if err != nil {
				return err
			}
			a = append(a, elem)
		}

		solve(a, k)

		testCases--
	}

	return nil
}

func solve(a []int, k *big.Int) {
	m := big.NewInt(0)
	if m.Mod(k, big.NewInt(2)).Cmp(big.NewInt(0)) == 0 {
		pprint(play(a, 2))
	} else {
		pprint(play(a, 1))
	}
}

func pprint(a []int) {
	for i, v := range a {
		fmt.Print(strconv.Itoa(v))
		if i != len(a)-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println()
}

func play(a []int, k int) []int {
	if k == 0 {
		return a
	}

	max := a[0]
	var p []int
	for _, v := range a {
		if v > max {
			max = v
		}
	}

	for j := 0; j < len(a); j++ {
		p = append(p, max-a[j])
	}
	return play(p, k-1)
}

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

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

const (
	oo  = 100000000
	mod = 1000000007
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

var (
	adj   [][]int
	depth []int
)

func pow(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	res := pow(a, b/2)
	res = mult(res, res)
	if b%2 == 1 {
		res = mult(res, a)
	}
	return res
}

func solve() {
	n, k := nextInt(), nextLong()
	arr := make([]int, n)
	for i := range arr {
		arr[i] = nextInt()
	}
	op(arr)
	k--
	if k%2 == 1 {
		op(arr)
	}
	for _, v := range arr {
		printf("%d ", v)
	}
	printf("\n")
}

func op(arr []int) {
	max := -1000000000
	for _, v := range arr {
		max = Max(max, v)
	}
	for i, v := range arr {
		arr[i] = max - v
	}
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case %d: ", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	var t, n int
	var k int64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &k)
		data := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &data[j])
		}
		if k%2 == 0 {
			do(data)
			do(data)
		} else {
			do(data)
		}
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", data[j])
		}
		fmt.Println()
	}
}

func do(a []int) {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	for i := 0; i < len(a); i++ {
		a[i] = max - a[i]
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		var n int
		s, _ := reader.ReadBytes('\n')
		pos := readInt(s, 0, &n)
		var k uint64
		readUint64(s, pos+1, &k)
		A := readNNums(reader, n)
		solve(n, k, A)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", A[i]))
		}
		buf.WriteByte('\n')
	}
	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 operate(n int, A []int) {
	x := A[0]
	for i := 1; i < n; i++ {
		if x < A[i] {
			x = A[i]
		}
	}
	for i := 0; i < n; i++ {
		A[i] = x - A[i]
	}
}

func solve(n int, k uint64, A []int) {
	operate(n, A)
	if k == 1 {
		return
	}

	k--

	if k&1 == 1 {
		operate(n, A)
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		n, k := in(), in()

		a := make([]int64, n)

		max := func() int64 {
			var m int64 = a[0]

			for i := range a {
				if a[i] > m {
					m = a[i]
				}
			}

			return m
		}

		for i := range a {
			a[i] = in()
		}

		d := max()
		k--
		for i := range a {
			a[i] = d - a[i]
		}

		r := k % 2

		if r == 1 {
			d := max()
			for i := range a {
				a[i] = d - a[i]
			}
		}

		for i := range a {
			fmt.Print(a[i], " ")
		}
		fmt.Println()
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k int64
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &k)
		a := make([]int64, n)
		max := int64(math.MinInt64)
		for j := int64(0); j < n; j++ {
			fmt.Fscan(in, &a[j])
			if a[j] > max {
				max = a[j]
			}
		}
		newMax := int64(math.MinInt64)
		for j := int64(0); j < n; j++ {
			a[j] = max - a[j]
			if k%2 == 1 {
				fmt.Print(a[j], " ")
			} else {
				if a[j] > newMax {
					newMax = a[j]
				}
			}
		}

		if k%2 == 0 {
			for j := int64(0); j < n; j++ {
				a[j] = newMax - a[j]
				fmt.Print(a[j], " ")
			}
			fmt.Println()
		}
	}
}

package main

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

var t, n int
var k int64

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

	fmt.Fscan(input, &t)

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

		fmt.Fscan(input, &n, &k)

		a := make([]int, n)

		mx := int(-1e9 - 5)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &a[i])
			if a[i] > mx {
				mx = a[i]
			}
		}

		mxx := int(-1e9 - 5)
		for i := 0; i < n; i++ {
			a[i] = mx - a[i]
			if a[i] > mxx {
				mxx = a[i]
			}
		}

		if k%2 == 0 {
			for i := 0; i < n; i++ {
				a[i] = mxx - a[i]
			}
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", a[i])
		}

		fmt.Println()
	}
}

package main

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

func main() {
	var t, n, k int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &k)
		data := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &data[j])
		}
		if k%2 == 0 {
			do(data)
			do(data)
		} else {
			do(data)
		}
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", data[j])
		}
		fmt.Println()
	}
}

func do(a []int) {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	for i := 0; i < len(a); i++ {
		a[i] = max - a[i]
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &k)
		a := make([]int64, n)
		max := int64(math.MinInt64)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			if a[j] > max {
				max = a[j]
			}
		}
		newMax := int64(math.MinInt64)
		for j := 0; j < n; j++ {
			a[j] = max - a[j]
			if k%2 == 1 {
				fmt.Print(a[j], " ")
			} else {
				if a[j] > newMax {
					newMax = a[j]
				}
			}
		}

		if k%2 == 0 {
			for j := 0; j < n; j++ {
				a[j] = newMax - a[j]
				fmt.Print(a[j], " ")
			}
			fmt.Println()
		}
	}
}

package main

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

var t, n, k int

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

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		fmt.Fscan(input, &n, &k)
		a := make([]int, n)

		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &a[i])
			if a[i] > mx {
				mx = a[i]
			}
		}

		if k%2 == 1 {
			for i := 0; i < n; i++ {
				a[i] = mx - a[i]
			}
		} else {
			for i := 0; i < n; i++ {
				if a[i] == mx {
					a[i] = 0
				}
			}
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", a[i])
		}

		fmt.Println()
	}
}

package main

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

var t, n, k int

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

	fmt.Fscan(input, &t)

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

		fmt.Fscan(input, &n, &k)

		a := make([]int, n)

		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &a[i])
			if a[i] > mx {
				mx = a[i]
			}
		}

		mxx := 0
		for i := 0; i < n; i++ {
			a[i] = mx - a[i]
			if a[i] > mxx {
				mxx = a[i]
			}
		}

		if k%2 == 0 {
			for i := 0; i < n; i++ {
				a[i] = mxx - a[i]
			}
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", a[i])
		}

		fmt.Println()
	}
}

package main

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

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

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

func run(args []string, s *bufio.Scanner) error {
	// Want to scan words instead of lines? s.Split(bufio.ScanWords)
	s.Split(bufio.ScanWords)
	s.Scan()

	testCases, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for testCases > 0 && s.Scan() {
		n, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}
		s.Scan()
		k, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		var a []int

		for i := 0; i < n && s.Scan(); i++ {
			elem, err := strconv.Atoi(s.Text())
			if err != nil {
				return err
			}
			a = append(a, elem)
		}

		solve(a, k)

		testCases--
	}

	return nil
}

// 0. Check if current permutation exists in the map
// 0a. If it does then the final array will look like loop[(k - loopStart) % loopLen]
// 1. Save current permutation in hash map
// 2. Find max value, d
// 3. for each value, value = d - value
// 4. GOTO 0.

func solve(a []int, k int) {
	m := make(map[string]int)

	for i := 0; i < k; i++ {
		arrKey := key(a)
		if loopStart, ok := m[arrKey]; ok {
			loopLen := i - loopStart
			index := (k - i) % loopLen
			pos := loopStart + index
			for ke, val := range m {
				if val == pos {
					printAns(ke)
					return
				}
			}
		} else {
			m[arrKey] = i
		}

		var max int = -1 * (2 << 30)
		for _, v := range a {
			if v > max {
				max = v
			}
		}

		for j := 0; j < len(a); j++ {
			a[j] = max - a[j]
		}
	}

	printAns(key(a))
}

func key(a []int) string {
	k := ""
	for i, v := range a {
		k += strconv.Itoa(v)
		if i != len(a) - 1 {
			k += "~"
		}
	}
	return k
}

func printAns(s string) {
	parts := strings.Split(s, "~")
	fmt.Println(strings.Join(parts, " "))
}

package main

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

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

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

func run(args []string, s *bufio.Scanner) error {
	// Want to scan words instead of lines? s.Split(bufio.ScanWords)
	s.Split(bufio.ScanWords)
	s.Scan()

	testCases, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for testCases > 0 && s.Scan() {
		n, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}
		s.Scan()
		k, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		var a []int

		for i := 0; i < n && s.Scan(); i++ {
			elem, err := strconv.Atoi(s.Text())
			if err != nil {
				return err
			}
			a = append(a, elem)
		}

		solve2(a, k)

		testCases--
	}

	return nil
}

// 0. Check if current permutation exists in the map
// 0a. If it does then the final array will look like loop[(k - loopStart) % loopLen]
// 1. Save current permutation in hash map
// 2. Find max value, d
// 3. for each value, value = d - value
// 4. GOTO 0.

func solve2(a []int, k int) {
	odd := play(a, 1)
	even := play(a, 2)

	if k % 2 == 0 {
		for i, v := range even {
			fmt.Print(strconv.Itoa(v))
			if i != len(even) - 1 {
				fmt.Print(" ")
			}
		}
		fmt.Println()
	} else {
		for i, v := range odd {
			fmt.Print(strconv.Itoa(v))
			if i != len(odd) - 1 {
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func play(a []int, k int) []int {
	if k == 0 {
		return a
	}

	max := a[0]
	var p []int
	for _, v := range a {
		if v > max {
			max = v
		}
	}

	for j := 0; j < len(a); j++ {
		p = append(p, max - a[j])
	}
	return play(p, k -1)
}

func solve(a []int, k int) {
	m := make(map[string]int)

	for i := 0; i < k; i++ {
		arrKey := key(a)
		if loopStart, ok := m[arrKey]; ok {
			loopLen := i - loopStart
			index := (k - i) % loopLen
			pos := loopStart + index
			for ke, val := range m {
				if val == pos {
					printAns(ke)
					return
				}
			}
		} else {
			m[arrKey] = i
		}

		max := a[0]
		for _, v := range a {
			if v > max {
				max = v
			}
		}

		for j := 0; j < len(a); j++ {
			a[j] = max - a[j]
		}
	}

	printAns(key(a))
}

func key(a []int) string {
	k := ""
	for i, v := range a {
		k += strconv.Itoa(v)
		if i != len(a) - 1 {
			k += "~"
		}
	}
	return k
}

func printAns(s string) {
	parts := strings.Split(s, "~")
	fmt.Println(strings.Join(parts, " "))
}


package main

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

type scanner struct {
	s *bufio.Scanner
}

func initScanner(filename string) scanner {
	//f, _ := os.Open(filename)
	f := os.Stdin
	return scanner{s: bufio.NewScanner(f)}
}

func (s scanner) ReadInt() int {
	s.s.Scan()
	val, _ := strconv.Atoi(s.s.Text())
	return val
}

func sum(x float64) float64 {
	return x * (x + 1) / 2
}

func Implode(glue string, args []int) string {
	data := make([]string, len(args))
	for i, s := range args {
		data[i] = fmt.Sprint(s)
	}
	return strings.Join(data, glue)
}

func main() {

	scanner := initScanner("input.txt")
	scanner.s.Split(bufio.ScanWords)

	a := scanner.ReadInt()
	b := scanner.ReadInt()

	x := 1
	for ; sum(float64(x)) < float64(a+b); x++ {
	}

	var outA []int
	var outB []int

	for limit := 1; x != 0 && limit < 10; x-- {
		aX := a
		aY := b
		limit++

		var aRes []int
		var bRes []int

		for tempX := x; tempX > 0; tempX--{
			if aX >= tempX {
				aX -= tempX
				aRes = append(aRes, tempX)
			} else {
				if aY >= tempX {
					aY -= tempX
					bRes = append(bRes, tempX)
				}
			}
		}

		if len(aRes)+len(bRes) > len(outA)+len(outB) {
			outA = aRes
			outB = bRes
		}
	}

	fmt.Println(len(outA))
	fmt.Println(Implode(" ", outA))
	fmt.Println(len(outB))
	fmt.Println(Implode(" ", outB))
}

//   C. Успеть все
//   https://codeforces.com/contest/1031/problem/C
//   tags: greedy
package main

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

type scanner struct {
	s *bufio.Scanner
}

func initScanner(filename string) scanner {
	//f, _ := os.Open(filename)
	f := os.Stdin
	return scanner{s: bufio.NewScanner(f)}
}

func (s scanner) ReadInt() int {
	s.s.Scan()
	val, _ := strconv.Atoi(s.s.Text())
	return val
}

func sum(x float64) float64 {
	return x * (x + 1) / 2
}

func Implode(glue string, args []int) string {
	data := make([]string, len(args))
	for i, s := range args {
		data[i] = fmt.Sprint(s)
	}
	return strings.Join(data, glue)
}

func main() {

	scanner := initScanner("input.txt")
	scanner.s.Split(bufio.ScanWords)

	a := scanner.ReadInt()
	b := scanner.ReadInt()

	x := 1
	for ; sum(float64(x)) < float64(a+b); x++ {
	}

	var outA []int
	var outB []int

	for limit := 0; x != 0 && limit < 2; x-- {
		aX := a
		aY := b
		limit++

		var aRes []int
		var bRes []int

		for tempX := x; tempX > 0; tempX--{
			if aX >= tempX {
				aX -= tempX
				aRes = append(aRes, tempX)
			} else {
				if aY >= tempX {
					aY -= tempX
					bRes = append(bRes, tempX)
				}
			}
		}

		if len(aRes)+len(bRes) > len(outA)+len(outB) {
			outA = aRes
			outB = bRes
		}
	}

	fmt.Println(len(outA))
	fmt.Println(Implode(" ", outA))
	fmt.Println(len(outB))
	fmt.Println(Implode(" ", outB))
}

package main

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

type scanner struct {
	s *bufio.Scanner
}

func initScanner(filename string) scanner {
	//f, _ := os.Open(filename)
	f := os.Stdin
	return scanner{s: bufio.NewScanner(f)}
}

func (s scanner) ReadInt() int {
	s.s.Scan()
	val, _ := strconv.Atoi(s.s.Text())
	return val
}

func sum(x float64) float64 {
	return x * (x + 1) / 2
}

func Implode(glue string, args []int) string {
	data := make([]string, len(args))
	for i, s := range args {
		data[i] = fmt.Sprint(s)
	}
	return strings.Join(data, glue)
}

func main() {

	scanner := initScanner("input.txt")
	scanner.s.Split(bufio.ScanWords)

	a := scanner.ReadInt()
	b := scanner.ReadInt()

	//fmt.Println(a, b)

	x := 1
	for ; sum(float64(x)) < float64(a+b); x++ {
	}

	for ; x != 1; x-- {
		aX := a
		aY := b

		var aRes []int
		var bRes []int

		for tempX := x; tempX > 0; tempX--{
			if aX >= tempX {
				aX -= tempX
				aRes = append(aRes, tempX)
			} else {
				if aY >= tempX {
					aY -= tempX
					bRes = append(bRes, tempX)
				}
			}
		}

		if aX+aY == 0 {
			fmt.Println(len(aRes))
			fmt.Println(Implode(" ", aRes))
			fmt.Println(len(bRes))
			fmt.Println(Implode(" ", bRes))
			return
		}
	}
}

package main

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

type scanner struct {
	s *bufio.Scanner
}

func initScanner(filename string) scanner {
	//f, _ := os.Open(filename)
	f := os.Stdin
	return scanner{s: bufio.NewScanner(f)}
}

func (s scanner) ReadInt() int {
	s.s.Scan()
	val, _ := strconv.Atoi(s.s.Text())
	return val
}

func sum(x float64) float64 {
	return x * (x + 1) / 2
}

func Implode(glue string, args []int) string {
	data := make([]string, len(args))
	for i, s := range args {
		data[i] = fmt.Sprint(s)
	}
	return strings.Join(data, glue)
}

func main() {

	scanner := initScanner("input.txt")
	scanner.s.Split(bufio.ScanWords)

	a := scanner.ReadInt()
	b := scanner.ReadInt()

	x := 1
	for ; sum(float64(x)) < float64(a+b); x++ {
	}

	var outA []int
	var outB []int

	for limit := 1; x != 1 && limit < 10; x-- {
		aX := a
		aY := b
		limit++

		var aRes []int
		var bRes []int

		for tempX := x; tempX > 0; tempX--{
			if aX >= tempX {
				aX -= tempX
				aRes = append(aRes, tempX)
			} else {
				if aY >= tempX {
					aY -= tempX
					bRes = append(bRes, tempX)
				}
			}
		}

		if len(aRes)+len(bRes) > len(outA)+len(outB) {
			outA = aRes
			outB = bRes
		}
	}

	fmt.Println(len(outA))
	fmt.Println(Implode(" ", outA))
	fmt.Println(len(outB))
	fmt.Println(Implode(" ", outB))
}

//   C. Успеть все
//   https://codeforces.com/contest/1031/problem/C
//   tags: greedy
package main

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

type scanner struct {
	s *bufio.Scanner
}

func initScanner(filename string) scanner {
	//f, _ := os.Open(filename)
	f := os.Stdin
	return scanner{s: bufio.NewScanner(f)}
}

func (s scanner) ReadInt() int {
	s.s.Scan()
	val, _ := strconv.Atoi(s.s.Text())
	return val
}

func sum(x float64) float64 {
	return x * (x + 1) / 2
}

func Implode(glue string, args []int) string {
	data := make([]string, len(args))
	for i, s := range args {
		data[i] = fmt.Sprint(s)
	}
	return strings.Join(data, glue)
}

func main() {

	scanner := initScanner("input.txt")
	scanner.s.Split(bufio.ScanWords)

	a := scanner.ReadInt()
	b := scanner.ReadInt()

	x := 1
	for ; sum(float64(x)) < float64(a+b); x++ {
	}

	var outA []int
	var outB []int

	for limit := 0; x != 0 && limit < 1; x-- {
		aX := a
		aY := b
		limit++

		var aRes []int
		var bRes []int

		for tempX := x; tempX > 0; tempX--{
			if aX >= tempX {
				aX -= tempX
				aRes = append(aRes, tempX)
			} else {
				if aY >= tempX {
					aY -= tempX
					bRes = append(bRes, tempX)
				}
			}
		}

		if len(aRes)+len(bRes) > len(outA)+len(outB) {
			outA = aRes
			outB = bRes
		}
	}

	fmt.Println(len(outA))
	fmt.Println(Implode(" ", outA))
	fmt.Println(len(outB))
	fmt.Println(Implode(" ", outB))
}


package main

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

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

	pow := func(x int64, n int) (res int64) {
		x %= mod
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return
	}

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		type pair struct{ l, r, x int }
		a := make([]pair, m)
		for i := range a {
			Fscan(in, &a[i].l, &a[i].r, &a[i].x)
		}
		//b := make([]int, m*2)
		ans := int64(0)
		for i := 0; i < 30; i++ {
			d := make([]int, n+2)
			for _, p := range a {
				if p.x>>i&1 == 0 {
					d[p.l]++
					d[p.r+1]--
				}
			}
			//sort.Ints(c)
			cnt0 := 0
			s := 0
			for _, v := range d {
				s+=v
				if s > 0 {
					cnt0++
				}
			}
			//pre := 1
			//for _, v := range c {
			//	if v>>1 > pre {
			//		if s > 0 {
			//			cnt0 += v>>1 - pre
			//		}
			//		pre = v >> 1
			//	}
			//	if v&1 > 0 {
			//		s++
			//	} else {
			//		s--
			//	}
			//}
			cnt1 := n - cnt0
			if cnt1 > 0 {
				cur := pow(2, cnt1-1) * pow(2, cnt0) % mod
				ans = (ans + cur<<i) % mod
			}
		}
		Fprintln(out, ans)
	}

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

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

}

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

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-- {
		var n, m int
		fmt.Fscan(in, &n, &m)

		var l, r, x, res, mod, pt int64
		mod = 1_000_000_007
		pt = 1
		for i := 0; i < n-1; i++ {
			pt = pt * 2 % mod
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &l, &r, &x)
			res |= x
		}
		res = (res % mod * pt) % mod

		fmt.Fprintln(out, res)
	}
}

package main

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

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

func solveCase() {
	var n, m, fr, to, sumOr int
	fmt.Fscan(in, &n, &m)
	var totalOr int64 = 0
	const mod = int64(1e9 + 7)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &fr, &to, &sumOr)
		totalOr = totalOr | int64(sumOr)
	}
	var ans = totalOr % mod
	for i := 1; i < n; i++ {
		ans = (ans * 2) % mod
	}
	fmt.Fprintln(out, ans)
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}

package main

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

const MOD int64 = 1e9+7

var n, m int

var l, r, x []int

var fact []int64

var twoN []int64

var inv []int64

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

	var t int

	fmt.Fscan(read, &t)

	precompute()

	//st := time.Now().UnixNano()

	for i := 0; i < t; i++ {
		fmt.Fscan(read, &n, &m)
		//n = 50000
	//	m = 50000

		l = make([]int, m)
		r = make([]int, m)
		x= make([]int, m)

		for j := 0; j < m; j++ {
			fmt.Fscan(read, &l[j], &r[j], &x[j])
			//l[j] = j + 1
			//r[j] = j + 1
			//x[j] = 0
		}

		ans := solve()

		fmt.Fprintln(w, ans)
	}
	w.Flush()

	//en := time.Now().UnixNano()

	//fmt.Println((en - st)/1000000)
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func precompute() {
	fact = make([]int64, 2e5 + 1)
	twoN = make([]int64, 2e5 + 1)

	inv = make([]int64, 2e5 + 1)

	var p int64 = 1

	for i := 0; i < 2e5 + 1; i++ {
		twoN[i] = p

		p = (p * 2) % MOD
	}

	fact[0] = 1

	for i := 1; i < 2e5 + 1; i++ {
		fact[i] = (fact[i - 1] * int64(i)) % MOD
	}

	for i := 0; i < 2e5 + 1; i ++ {
		inv[i] = modInverse(fact[i], MOD)
	}
}

func solve() int64 {
	//1 2 5 3 6 7

	var cnt [31]int

	var pairs []*pair

	for i := 0; i < m; i++ {
		pairs = append(pairs, &pair{l[i], i})
	}
	sort.Sort(ByV(pairs))

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

		rmz := -1

		for j := 0; j < m; j++ {
			p := pairs[j]

			left, right := p.v, r[p.id]
			left--
			right--

			xor := x[p.id]

			b := xor >> uint(i) & 0x1

			if b == 0 {
				if rmz == -1 {
					cnt[i] += left

				} else {

					if left > rmz {
						cnt[i] += left - rmz - 1
					}
				}

				if right > rmz {
					rmz = right
				}
			}
		}
		if rmz == -1 {
			cnt[i] += n

		} else if rmz < n - 1 {
			cnt[i] += (n -1 - rmz)
		}
	}

	var ans int64

	for j := 0; j < 30; j++ {
		o := cnt[j]

		if o > n {
			panic("can't be")
		}

		z := n - o

		//1 1 1 0 0 1

		var s int64

		for i := 1; i <= o; i+=2 {
			//i choose o

			nchoose := ((fact[o] * inv[i] % MOD) * inv[o - i]) % MOD

			temp := (nchoose * twoN[z]) % MOD

			s = (s + temp) % MOD
		}

		s = (s * twoN[j]) % MOD

		ans = (ans + s) % MOD
	}

	return ans
}

func modInverse(a int64, m int64) int64 {
	var x, y int64
	g := gcdExtended(a, m, &x, &y)

	if g != 1 {
		panic( "Inverse doesn't exist")
	} else {

		// m is added to handle negative x
		res := (x % m + m) % m
		return res
	}
}

func gcdExtended(a int64, b int64, x *int64, y *int64) int64 {

	// Base Case
	if a == 0 {
		*x, *y = 0,1
		return b
	}

	// To store results of recursive call
	var x1, y1 int64
	gcd := gcdExtended(b%a, a, &x1, &y1);

	// Update x and y using results of recursive
	// call
	*x = y1 - (b/a)*x1;
	*y = x1
	return gcd
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

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

const mod = 1e9 + 7

var fac, invfac []int64

func bitAt(n, bit int64) int {
	if n&(1<<bit) == 0 {
		return 0
	}
	return 1
}

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func solveForBit(n int, bit int64, segs [][3]int) int64 {
	res := make([]int, n+1)
	for _, seg := range segs {
		l, r, or := seg[0], seg[1], int64(seg[2])
		if bitAt(or, bit) == 0 {
			res[l-1]++
			res[r]--
		}
	}
	for i := 1; i < n; i++ {
		res[i] += res[i-1]
	}

	var cnt0, cnt1 int64
	for _, i := range res[:len(res)-1] {
		if i > 0 {
			cnt0++
		} else {
			cnt1++
		}
	}
	if cnt1 == 0 {
		return 0
	}
	var totalCases = (binpow(2, cnt0) * binpow(2, cnt1-1)) % mod
	ans := (totalCases * binpow(2, bit)) % mod
	return ans
}

func solveC() {
	var n, m int
	scan(&n, &m)
	segs := make([][3]int, m)
	for i := range segs {
		for j := 0; j < 3; j++ {
			scan(&segs[i][j])
		}
	}

	fac = make([]int64, n+1)
	fac[0] = 1
	fac[1] = 1
	for i := 2; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i)
		fac[i] %= mod
	}
	invfac = make([]int64, n+1)
	for i := 0; i <= n; i++ {
		invfac[i] = binpow(fac[i], mod-2)
	}

	var ans int64
	for bit := int64(0); bit < 30; bit++ {
		ans += solveForBit(n, bit, segs)
		ans %= mod
	}

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

package main

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

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

const mod = 1e9 + 7

var fac, invfac []int64

func bitAt(n, bit int64) int {
	if n&(1<<bit) == 0 {
		return 0
	}
	return 1
}

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func solveForBit(n int, bit int64, segs [][3]int) int64 {
	res := make([]int, n+1)
	for _, seg := range segs {
		l, r, or := seg[0], seg[1], int64(seg[2])
		if bitAt(or, bit) == 0 {
			res[l-1]++
			res[r]--
		}
	}
	for i := 1; i < n; i++ {
		res[i] += res[i-1]
	}

	var cnt0, cnt1 int64
	for _, i := range res[:len(res)-1] {
		if i > 0 {
			cnt0++
		} else {
			cnt1++
		}
	}

	var zeroes, totalCases int64 = binpow(2, cnt0), 0
	for k := int64(1); k <= cnt1; k += 2 {
		ones := ((fac[cnt1] * invfac[k]) % mod * invfac[cnt1-k]) % mod
		totalCases += (ones * zeroes) % mod
		totalCases %= mod
	}
	ans := (totalCases * binpow(2, bit)) % mod
	return ans
}

/*
	1: 1 1 1 0 0 => cases: 4 ans: 4  = 1 1 1 0 0
	2: 1 1 1 0 1 => cases: 8 ans: 16 = 2 2 2 0 2
	4: 1 1 1 0 0 => cases: 4 ans: 16 = 4 4 4 0 0

	[7, 7, 7, 0, 2]
*/

func solveC() {
	var n, m int
	scan(&n, &m)
	segs := make([][3]int, m)
	for i := range segs {
		for j := 0; j < 3; j++ {
			scan(&segs[i][j])
		}
	}

	fac = make([]int64, n+1)
	fac[0] = 1
	fac[1] = 1
	for i := 2; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i)
		fac[i] %= mod
	}
	invfac = make([]int64, n+1)
	for i := 0; i <= n; i++ {
		invfac[i] = binpow(fac[i], mod-2)
	}

	var ans int64
	for bit := int64(0); bit < 30; bit++ {
		ans += solveForBit(n, bit, segs)
		ans %= mod
	}

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
	// n := 5
	// ans := 0
	// for mask := 1; mask < (1 << n); mask++ {
	// 	xor := 0
	// 	for i := 0; i < n; i++ {
	// 		if bitAt(int64(mask), int64(i)) == 1 {
	// 			xor ^= i
	// 		}
	// 	}
	// 	ans += xor
	// }
	// printf("%d", ans)
}

package main

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

const MOD int64 = 1e9+7

var n, m int

var l, r, x []int

var fact []int64

var twoN []int64

var inv []int64

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

	var t int

	fmt.Fscan(read, &t)

	precompute()

	//st := time.Now().UnixNano()

	for i := 0; i < t; i++ {
		fmt.Fscan(read, &n, &m)
		//n = 50000
		//m = 50000

		l = make([]int, m)
		r = make([]int, m)
		x= make([]int, m)

		for j := 0; j < m; j++ {
			fmt.Fscan(read, &l[j], &r[j], &x[j])
			//l[j] = j + 1
			//r[j] = j + 1
			//x[j] = 0
		}

		ans := solve()

		fmt.Fprintln(w, ans)
	}
	w.Flush()

	//en := time.Now().UnixNano()

	//fmt.Println((en - st)/1000000)
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func precompute() {
	fact = make([]int64, 2e5 + 1)
	twoN = make([]int64, 2e5 + 1)

	inv = make([]int64, 2e5 + 1)

	var p int64 = 1

	for i := 0; i < 2e5 + 1; i++ {
		twoN[i] = p

		p = (p * 2) % MOD
	}

	fact[0] = 1

	for i := 1; i < 2e5 + 1; i++ {
		fact[i] = (fact[i - 1] * int64(i)) % MOD
	}

	for i := 0; i < 2e5 + 1; i ++ {
		inv[i] = modInverse(fact[i], MOD)
	}
}

func solve() int64 {
	//1 2 5 3 6 7

	var cnt [31]int

	order := make([]int, m)
	for i := 0; i < m; i++ {
		order[i] = i
	}
	sort.Slice(order, func(i, j int) bool {
		return l[i] < l[j]
	})

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

		rmz := -1

		for j := 0; j < m; j++ {
			left, right := l[order[j]], r[order[j]]
			left--
			right--

			xor := x[order[j]]

			b := xor >> uint(i) & 0x1

			if b == 0 {
				if rmz == -1 {
					cnt[i] += left

				} else {

					if left > rmz {
						cnt[i] += left - rmz - 1
					}
				}

				if right > rmz {
					rmz = right
				}
			}
		}
		if rmz == -1 {
			cnt[i] += n

		} else if rmz < n - 1 {
			cnt[i] += (n -1 - rmz)
		}
	}

	var ans int64

	for j := 0; j < 30; j++ {
		o := cnt[j]

		if o > n {
			panic("can't be")
		}

		z := n - o

		//1 1 1 0 0 1

		var s int64

		for i := 1; i <= o; i+=2 {
			//i choose o

			nchoose := ((fact[o] * inv[i] % MOD) * inv[o - i]) % MOD

			temp := (nchoose * twoN[z]) % MOD

			s = (s + temp) % MOD
		}

		s = (s * twoN[j]) % MOD

		ans = (ans + s) % MOD
	}

	return ans
}

func modInverse(a int64, m int64) int64 {
	var x, y int64
	g := gcdExtended(a, m, &x, &y)

	if g != 1 {
		panic( "Inverse doesn't exist")
	} else {

		// m is added to handle negative x
		res := (x % m + m) % m
		return res
	}
}

func gcdExtended(a int64, b int64, x *int64, y *int64) int64 {

	// Base Case
	if a == 0 {
		*x, *y = 0,1
		return b
	}

	// To store results of recursive call
	var x1, y1 int64
	gcd := gcdExtended(b%a, a, &x1, &y1);

	// Update x and y using results of recursive
	// call
	*x = y1 - (b/a)*x1;
	*y = x1
	return gcd
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

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

const mod = 1e9 + 7

var fac, invfac []int64

func bitAt(n, bit int64) int {
	if n&(1<<bit) == 0 {
		return 0
	}
	return 1
}

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func solveForBit(n int, bit int64, segs [][3]int) int64 {
	res := make([]int, n+1)
	for _, seg := range segs {
		l, r, or := seg[0], seg[1], int64(seg[2])
		if bitAt(or, bit) == 0 {
			res[l-1]++
			res[r]--
		}
	}
	for i := 1; i < n; i++ {
		res[i] += res[i-1]
	}

	var cnt0, cnt1 int64
	for _, i := range res[:len(res)-1] {
		if i > 0 {
			cnt0++
		} else {
			cnt1++
		}
	}

	var totalCases int64
	for k := int64(1); k <= cnt1; k += 2 {
		x1 := (fac[cnt1] * invfac[k]) % mod
		x2 := (x1 * invfac[cnt1-k]) % mod
		totalCases += x2
		totalCases %= mod
	}

	return (totalCases * binpow(2, bit)) % mod
}

func solveC() {
	var n, m int
	scan(&n, &m)
	segs := make([][3]int, m)
	for i := range segs {
		for j := 0; j < 3; j++ {
			scan(&segs[i][j])
		}
	}

	fac = make([]int64, n+1)
	fac[0] = 1
	fac[1] = 1
	for i := 2; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i)
		fac[i] %= mod
	}
	invfac = make([]int64, n+1)
	for i := 0; i <= n; i++ {
		invfac[i] = binpow(fac[i], mod-2)
	}

	var ans int64
	for bit := int64(0); bit < 30; bit++ {
		ans += solveForBit(n, bit, segs)
		ans %= mod
	}

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

package main

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

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

const mod = 1e9 + 7

var fac, invfac []int64

func bitAt(n, bit int64) int {
	if n&(1<<bit) == 0 {
		return 0
	}
	return 1
}

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func solveForBit(n int, bit int64, segs [][3]int) int64 {
	res := make([]int, n+1)
	for _, seg := range segs {
		l, r, or := seg[0], seg[1], int64(seg[2])
		if bitAt(or, bit) == 0 {
			res[l-1]++
			res[r]--
		}
	}
	for i := 1; i < n; i++ {
		res[i] += res[i-1]
	}

	var cnt0, cnt1 int64
	for _, i := range res[:len(res)-1] {
		if i > 0 {
			cnt0++
		} else {
			cnt1++
		}
	}

	var ans int64
	for k := int64(1); k <= cnt1; k += 2 {
		totalCases := ((fac[cnt1] * invfac[k]) % mod * invfac[cnt1-k]) % mod
		ans += (totalCases * binpow(2, bit)) % mod
		ans %= mod
	}

	return ans
}

func solveC() {
	var n, m int
	scan(&n, &m)
	segs := make([][3]int, m)
	for i := range segs {
		for j := 0; j < 3; j++ {
			scan(&segs[i][j])
		}
	}

	fac = make([]int64, n+1)
	fac[1] = 1
	for i := 2; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i)
		fac[i] %= mod
	}
	invfac = make([]int64, n+1)
	for i := 1; i <= n; i++ {
		invfac[i] = binpow(fac[i], mod-2)
	}

	var ans int64
	for bit := int64(0); bit < 30; bit++ {
		ans += solveForBit(n, bit, segs)
		ans %= mod
	}

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solveC()
	}
}

package main

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

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

const mod = 1e9 + 7

func bitAt(n int, bit int) int {
	if n&(1<<bit) == 0 {
		return 0
	}
	return 1
}

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func solveForBit(n int, bit int, segs [][3]int) int64 {
	res := make([]int, n+1)
	for _, seg := range segs {
		l, r, or := seg[0], seg[1], seg[2]
		if bitAt(or, bit) == 0 {
			res[l-1]++
			res[r]--
		}
	}
	for i := 1; i < n; i++ {
		res[i] += res[i-1]
	}

	var cnt0, cnt1 int64
	for _, i := range res[:len(res)-1] {
		if i > 0 {
			cnt0++
		} else {
			cnt1++
		}
	}

	val := binpow(2, int64(bit))
	totalCases := (binpow(2, cnt0) * (binpow(2, cnt1) - 1)) % mod
	return (totalCases * val) % mod
}

func C() {
	var n, m int
	scan(&n, &m)
	segs := make([][3]int, m)
	for i := range segs {
		for j := 0; j < 3; j++ {
			scan(&segs[i][j])
		}
	}

	var ans int64
	for bit := 0; bit < 30; bit++ {
		ans += solveForBit(n, bit, segs)
		ans %= mod
	}

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

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		C()
	}
}

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-- {
		var n, m int
		fmt.Fscan(in, &n, &m)

		var l, r, x, res, mod, pt int64
		mod = 1_000_000_007
		pt = 1
		for i := 0; i < n-1; i++ {
			pt = pt * 2
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &l, &r, &x)
			res |= x
		}
		res = (res % mod * pt % mod) % mod

		fmt.Fprintln(out, res)
	}
}


package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"time"
)

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int
	for I(&n, &k) == nil {
		rand.Seed(time.Now().Unix())
		solve(n, k)
	}
	w.Flush()
}

var tree []int

func update(i, val int) {
	for i < len(tree) {
		tree[i] += val
		i += i & -i
	}
}

func sum(i int) int {
	var s int
	for i > 0 {
		s += tree[i]
		i -= i & -i
	}
	return s
}

type Node struct {
	Left     *Node
	Value    int
	Priority int
	Right    *Node
}

func newNode(value int) *Node {
	return &Node{nil, value, rand.Intn(100), nil}
}

func rightRotate(node *Node) *Node {
	res := node.Left
	node.Left = res.Right
	res.Right = node
	return res
}
func leftRotate(node *Node) *Node {
	res := node.Right
	node.Right = res.Left
	res.Left = node
	return res
}

func insert(node *Node, value int) *Node {
	if node == nil {
		return newNode(value)
	}
	if node.Value > value {
		node.Left = insert(node.Left, value)
		if node.Left.Priority > node.Priority {
			node = rightRotate(node)
		}
		return node
	}
	node.Right = insert(node.Right, value)
	if node.Right.Priority > node.Priority {
		node = leftRotate(node)
	}
	return node
}

var hi, lo *Node

func higher(node *Node, value int) *Node {
	hi = new(Node)
	doHigher(node, value)
	return hi
}

func doHigher(node *Node, value int) {
	if node == nil {
		return
	}
	if node.Value > value {
		hi = node
		doHigher(node.Left, value)
	} else {
		lo = node
		doHigher(node.Right, value)
	}
}

func solve(n, k int) {
	MAX := n + 2
	tree = make([]int, MAX)
	node := &Node{nil, 0, 100, nil}
	insert(node, n+1)
	pos := make([]int, MAX)
	nrm := make([]bool, MAX)
	for i := 1; i <= n; i++ {
		pos[readInt()] = i
	}
	for i := 0; i < k; i++ {
		nrm[readInt()] = true
	}
	var ans int64
	for i := 1; i <= n; i++ {
		if nrm[i] {
			insert(node, pos[i])
		} else {
			r := higher(node, pos[i])
			l := lo
			rr, ll := r.Value-1, l.Value
			ans += int64(rr) - int64(ll) - int64(sum(rr)) + int64(sum(ll))
			update(pos[i], 1)
		}
	}
	O(ans, "\n")
}

func readInt() int {
	var o bool
	var i int
	b, err := r.ReadByte()
	for err == nil {
		if b != ' ' && b != '\n' && b != '\r' {
			i = i*10 + int(b) - 48
			o = true
		} else if o {
			break
		}
		b, err = r.ReadByte()
	}
	return i
}

package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"time"
)

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int
	for I(&n, &k) == nil {
		rand.Seed(time.Now().Unix())
		solve(n, k)
	}
	w.Flush()
}

var tree []int

func update(i, val int) {
	for i < len(tree) {
		tree[i] += val
		i += i & -i
	}
}

func sum(i int) int {
	var s int
	for i > 0 {
		s += tree[i]
		i -= i & -i
	}
	return s
}

type Node struct {
	Left     *Node
	Value    int
	Priority int
	Right    *Node
}

func newNode(value int) *Node {
	return &Node{nil, value, rand.Intn(100), nil}
}

func rightRotate(node *Node) *Node {
	res := node.Left
	node.Left = res.Right
	res.Right = node
	return res
}
func leftRotate(node *Node) *Node {
	res := node.Right
	node.Right = res.Left
	res.Left = node
	return res
}

func insert(node *Node, value int) *Node {
	if node == nil {
		return newNode(value)
	}
	if node.Value > value {
		node.Left = insert(node.Left, value)
		if node.Left.Priority > node.Priority {
			node = rightRotate(node)
		}
		return node
	}
	node.Right = insert(node.Right, value)
	if node.Right.Priority > node.Priority {
		node = leftRotate(node)
	}
	return node
}

var hi, lo *Node

func higher(node *Node, value int) *Node {
	hi = new(Node)
	doHigher(node, value)
	return hi
}

func doHigher(node *Node, value int) {
	if node == nil {
		return
	}
	if node.Value > value {
		hi = node
		doHigher(node.Left, value)
	} else {
		lo = node
		doHigher(node.Right, value)
	}
}

func solve(n, k int) {
	MAX := n + 2
	tree = make([]int, MAX)
	node := &Node{nil, 0, 100, nil}
	insert(node, n+1)
	pos := make([]int, MAX)
	nrm := make([]bool, MAX)
	r.ReadLine()
	for i := 1; i <= n; i++ {
		var delim byte = ' '
		if i == n {
			delim = '\n'
		}
		ooo, _ := r.ReadBytes(delim)
		pos[toInt(ooo)] = i
	}
	for i := 0; i < k; i++ {
		var delim byte = ' '
		if i == k-1 {
			delim = '\n'
		}
		ooo, _ := r.ReadBytes(delim)
		nrm[toInt(ooo)] = true
	}
	var ans int64
	for i := 1; i <= n; i++ {
		if nrm[i] {
			insert(node, pos[i])
		} else {
			r := higher(node, pos[i])
			l := lo
			rr, ll := r.Value-1, l.Value
			ans += int64(rr)
			ans -= int64(ll)
			ans -= int64(sum(rr))
			ans += int64(sum(ll))
			update(pos[i], 1)
		}
	}
	O(ans, "\n")
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		if v != ' ' && v != '\n' && v != '\r' {
			n = n*10 + int(v-'0')
		}
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"time"
)

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int
	for I(&n, &k) == nil {
		rand.Seed(time.Now().Unix())
		solve(n, k)
	}
	w.Flush()
}

var tree []int

func update(i, val int) {
	for i < len(tree) {
		tree[i] += val
		i += i & -i
	}
}

func sum(i int) int {
	var s int
	for i > 0 {
		s += tree[i]
		i -= i & -i
	}
	return s
}

type Node struct {
	Left     *Node
	Value    int
	Priority int
	Right    *Node
}

func newNode(value int) *Node {
	return &Node{nil, value, rand.Intn(100), nil}
}

func rightRotate(node *Node) *Node {
	res := node.Left
	node.Left = res.Right
	res.Right = node
	return res
}
func leftRotate(node *Node) *Node {
	res := node.Right
	node.Right = res.Left
	res.Left = node
	return res
}

func insert(node *Node, value int) *Node {
	if node == nil {
		return newNode(value)
	}
	if node.Value > value {
		node.Left = insert(node.Left, value)
		if node.Left.Priority > node.Priority {
			node = rightRotate(node)
		}
		return node
	}
	node.Right = insert(node.Right, value)
	if node.Right.Priority > node.Priority {
		node = leftRotate(node)
	}
	return node
}

var hi, lo *Node

func higher(node *Node, value int) *Node {
	hi = new(Node)
	doHigher(node, value)
	return hi
}

func doHigher(node *Node, value int) {
	if node == nil {
		return
	}
	if node.Value > value {
		hi = node
		doHigher(node.Left, value)
	} else {
		lo = node
		doHigher(node.Right, value)
	}
}

func solve(n, k int) {
	MAX := n + 2
	tree = make([]int, MAX)
	node := &Node{nil, 0, 100, nil}
	insert(node, n+1)
	pos := make([]int, MAX)
	nrm := make([]bool, MAX)
	for i := 1; i <= n; i++ {
		pos[readInt(i == n)] = i
	}
	for i := 0; i < k; i++ {
		nrm[readInt(i == k-1)] = true
	}
	var ans int64
	for i := 1; i <= n; i++ {
		if nrm[i] {
			insert(node, pos[i])
		} else {
			r := higher(node, pos[i])
			l := lo
			rr, ll := r.Value-1, l.Value
			ans += int64(rr)
			ans -= int64(ll)
			ans -= int64(sum(rr))
			ans += int64(sum(ll))
			update(pos[i], 1)
		}
	}
	O(ans, "\n")
}

func readInt(endl bool) (n int) {
	var delim byte = ' '
	if endl {
		delim = '\n'
	}
	buf, _ := r.ReadBytes(delim)
	for _, v := range buf {
		if v != ' ' && v != '\n' && v != '\r' {
			n = n*10 + int(v-'0')
		}
	}
	return
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, k int
	for I(&n, &k) == nil {
		solve(n, k)
	}
	w.Flush()
}

var tree []int

func update(i, val int) {
	for i < len(tree) {
		tree[i] += val
		i += i & -i
	}
}

func sum(i int) int {
	var s int
	for i > 0 {
		s += tree[i]
		i -= i & -i
	}
	return s
}

type Node struct {
	Left  *Node
	Value int
	Right *Node
}

func insert(node *Node, value int) *Node {
	if node == nil {
		return &Node{nil, value, nil}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value)
		return node
	}
	node.Right = insert(node.Right, value)
	return node
}

var hi *Node

func higher(node *Node, value int) *Node {
	hi = new(Node)
	doHigher(node, value)
	return hi
}

func doHigher(node *Node, value int) {
	if node == nil {
		return
	}
	if node.Value > value {
		hi = node
		doHigher(node.Left, value)
	} else {
		doHigher(node.Right, value)
	}
}

var lo *Node

func lower(node *Node, value int) *Node {
	lo = new(Node)
	doLower(node, value)
	return lo
}

func doLower(node *Node, value int) {
	if node == nil {
		return
	}
	if node.Value < value {
		lo = node
		doLower(node.Right, value)
	} else {
		doLower(node.Left, value)
	}
}

func solve(n, k int) {
	MAX := n + 10
	tree = make([]int, MAX)
	node := new(Node)
	insert(node, 0)
	insert(node, n+1)
	pos := make([]int, MAX)
	nrm := make([]bool, MAX)
	var tmp int
	for i := 1; i <= n; i++ {
		I(&tmp)
		pos[tmp] = i
	}
	for i := 0; i < k; i++ {
		I(&tmp)
		nrm[tmp] = true
	}
	var ans int
	for i := 1; i <= n; i++ {
		if nrm[i] {
			insert(node, pos[i])
		} else {
			r := higher(node, pos[i])
			l := lower(node, pos[i])
			rr, ll := r.Value-1, l.Value
			ans += rr - ll - (sum(rr) - sum(ll))
			update(pos[i], 1)
		}
	}
	O(ans, "\n")
}


package main

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

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

	var n, k, v, w int
	Fscan(in, &n, &k)
	if n < 4 {
		Fprint(out, "No")
		return
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n)
	centers := map[int]int{}
	for i, gi := range g {
		if len(gi) == 1 {
			vis[i] = true
			centers[gi[0]]++
		}
	}
	for {
		k--
		newCenters := map[int]int{}
		for v, cnt1 := range centers {
			if cnt1 < 3 {
				Fprint(out, "No")
				return
			}
			ct := -1
			for _, w := range g[v] {
				if !vis[w] {
					if centers[w] > 0 || ct != -1 {
						Fprint(out, "No")
						return
					}
					ct = w
				}
			}
			if ct == -1 {
				if k == 0 {
					Fprint(out, "Yes")
				} else {
					Fprint(out, "No")
				}
				return
			}
			vis[v] = true
			newCenters[ct]++
		}
		centers = newCenters
	}
}

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

package main

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

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

	var n, k, v, w int
	Fscan(in, &n, &k)
	if n < 4 {
		Fprint(out, "No")
		return
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n)
	centers := map[int]int{}
	for i, gi := range g {
		if len(gi) == 1 {
			vis[i] = true
			centers[gi[0]]++
		}
	}
	for {
		k--
		newCenters := map[int]int{}
		for v, cnt1 := range centers {
			if cnt1 < 3 {
				Fprint(out, "No")
				return
			}
			ct := -1
			for _, w := range g[v] {
				if vis[w] {
					cnt1++
				} else {
					if centers[w] > 0 || ct != -1 {
						Fprint(out, "No")
						return
					}
					ct = w
				}
			}
			if ct == -1 {
				if k == 0 {
					Fprint(out, "Yes")
				} else {
					Fprint(out, "No")
				}
				return
			}
			vis[v] = true
			newCenters[ct]++
		}
		centers = newCenters
	}
}

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

package main

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

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

	var n, k, v, w, ct int
	Fscan(in, &n, &k)
	if n < 4 {
		Fprint(out, "No")
		return
	}
	g := make([][]int, n)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n)
	centers := map[int]bool{}
	for i, gi := range g {
		if len(gi) == 1 {
			vis[i] = true
			centers[gi[0]] = true
		}
	}
	for {
		k--
		newCenters := map[int]bool{}
		for v := range centers {
			cnt1, cnt2 := 0, 0
			for _, w := range g[v] {
				if vis[w] {
					cnt1++
				} else {
					if centers[w] {
						Fprint(out, "No")
						return
					}
					cnt2++
					ct = w
				}
			}
			if cnt1 < 3 || cnt2 > 1 {
				Fprint(out, "No")
				return
			}
			if cnt2 == 0 {
				if k == 0 {
					Fprint(out, "Yes")
				} else {
					Fprint(out, "No")
				}
				return
			}
			vis[v] = true
			newCenters[ct] = true
		}
		centers = newCenters
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1067B(_r io.Reader, _w io.Writer) (ans bool) {
	in := bufio.NewReader(_r)
	defer func() {
		if ans {
			Fprint(_w, "Yes")
		} else {
			Fprint(_w, "No")
		}
	}()

	var n, k, v, w int
	Fscan(in, &n, &k)
	if n < 4 {
		return false
	}
	g := make([][]int, n+1)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vis := make([]bool, n+1)
	centers := map[int]int{}
	for i, gi := range g {
		if len(gi) == 1 {
			vis[i] = true
			centers[gi[0]]++
		}
	}
	for {
		k--
		newCenters := map[int]int{}
		for v, cnt1 := range centers {
			if cnt1 < 3 {
				return false
			}
			ct := 0
			for _, w := range g[v] {
				if !vis[w] {
					if ct != 0 || centers[w] > 0 {
						return false
					}
					ct = w
				}
			}
			if ct == 0 {
				return k == 0
			}
			vis[v] = true
			newCenters[ct]++
		}
		centers = newCenters
	}
}

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

package main

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

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

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

	vis := make([]bool, n)
	centers := map[int]bool{}
	for i, gi := range g {
		if len(gi) == 1 {
			vis[i] = true
			centers[gi[0]] = true
		}
	}
	for {
		k--
		newCenters := map[int]bool{}
		for v := range centers {
			cnt1, cnt2 := 0, 0
			for _, w := range g[v] {
				if vis[w] {
					cnt1++
				} else {
					cnt2++
					ct = w
				}
			}
			if cnt1 < 3 || cnt2 > 1 {
				Fprint(out, "No")
				return
			}
			if cnt2 == 0 {
				if k == 0 {
					Fprint(out, "Yes")
				} else {
					Fprint(out, "No")
				}
				return
			}
			vis[v] = true
			newCenters[ct] = true
		}
		centers = newCenters
	}
}

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


package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		d := ScanInt()

		var p, q int

		for p = 1 + d; ; p++ {
			isPrime := true

			for i := 2; isPrime && i*i <= p; i++ {
				if p%i == 0 {
					isPrime = false
				}
			}

			if isPrime {
				break
			}
		}

		for q = p + d; ; q++ {
			isPrime := true

			for i := 2; isPrime && i*i <= q; i++ {
				if q%i == 0 {
					isPrime = false
				}
			}

			if isPrime {
				break
			}
		}

		fmt.Println(p * q)
	}
}

package main

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

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

	// Sieve of Eratosthenes
	notPrime := make([]bool, 1000005)
	for i := 2; i < len(notPrime); i++ {
		if !notPrime[i] {
			for j := i * 2; j < len(notPrime); j += i {
				notPrime[j] = true
			}
		}
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var d int
		Fscan(in, &d)

		first := 1 + d
		for notPrime[first] {
			first++
		}
		second := first + d
		for notPrime[second] {
			second++
		}
		Fprintln(out, first * second)
	}

}

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

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

package main

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

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

	// Fill the prime table
	isPrime := make([]bool, 1000005)
	for i, _ := range isPrime {
		isPrime[i] = true
	}
	for i := 2; i < len(isPrime); i++ {
		if isPrime[i] {
			for j := i * 2; j < len(isPrime); j += i {
				isPrime[j] = false
			}
		}
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var d int
		Fscan(in, &d)

		first := 1 + d
		for !isPrime[first] {
			first++
		}
		second := first + d
		for !isPrime[second] {
			second++
		}
		Fprintln(out, first * second)
	}

}

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

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

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &d)

		solve(d)

	}

}

func solve(d int) {

	front := d + 1

	for !PrimeOrNot(front) {
		front++
	}

	//fmt.Println(front)

	behind := front + d

	for !PrimeOrNot(behind) {
		behind++
	}

	//fmt.Println(behind)

	fmt.Fprintln(out, front*behind)

}

//判斷是否為質數
func PrimeOrNot(num int) bool {

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

package main

import "fmt"

func main() {
	var (
		t, d int
		ans  []int
	)
	fmt.Scan(&t)

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

	for _, i := range ans {
		fmt.Println(i)
	}
}

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

func solve(d int) int {
	ans := [3]int{1}

	for i := 1; i < 3; i++ {
		for x := ans[i-1] + d; ; x++ {
			if isPrime(x) {
				ans[i] = x
				break
			}
		}
	}

	return ans[2] * ans[1]
}

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, 1e6), 1e6)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

var sieve = make([]bool, 20015)

func init() {
	for i := 2; i < 20015; i++ {
		for j := i + i; j < len(sieve); j += i {
			sieve[j] = true
		}
	}
}

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

func sol(d int64) int64 {
	d2 := nextPrime(1 + d)
	d3 := nextPrime(d2 + d)
	return d2 * d3
}

func nextPrime(from int64) int64 {
	for i := from; i < int64(len(sieve)); i++ {
		if !sieve[i] {
			return i
		}
	}
	panic("x")
}

package main

import "fmt"
var arr [20100]bool
func erat()int{
	n:=len(arr)
	for i:=2;i<n;i++{
		arr[i] = true
	}
	p:=2
	for p*p<n{
		if arr[p] == true{
			for j:=2;j*p<n;j++{
				arr[p*j]=false
			}
		}
		for i:=p+1;;i++{
			if arr[i]==true{
				p = i
				break
			}
		}
	}
	return -1
}
func find(d int) int{
	for i:=d;;i++{
		if arr[i]==true{
			return i
		}
	}
}
func main(){
	var t,d int
	erat()
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		fmt.Scan(&d)
			erd:=find(1+d)
			fmt.Println(erd*find(erd+d))

	}

}

package main

import "fmt"

func main(){
	var t,d int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		fmt.Scan(&d)
		fmt.Println((1+d)*(1+2*d))
	}

}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var d int
		Fscan(in, &d)

		Fprintln(out, (1+d) * (1+2*d))
	}

}

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

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

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		d := ScanInt()

		if d == 1 {
			fmt.Println(6)
		} else {
			for p := 3 + d; ; p++ {
				isPrime := true

				for i := 2; isPrime && i*i <= p; i++ {
					if p%i == 0 {
						isPrime = false
					}
				}

				if isPrime {
					fmt.Println(3 * p)
					break
				}
			}
		}
	}
}

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &d)

		solve(d)

	}

}

func solve(d int) {

	fmt.Fprintln(out, (d+1)*((d+1)+d))

}


package main

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

func main() {
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	var n, k, advance, back int
	var colMax, rowMax, max = 0, 0, 0
	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	var buf []byte
	// instantiate field
	field := make([][]int, n)
	for i := range field {
		field[i] = make([]int, n)
	}

	for i := range field {
		buf, _ = reader.ReadBytes('\n')
		for j := range buf {
			switch buf[j] {
			case '#':
				field[i][j] = -1
			case '.':
				// upwards
				if i - (k - 1) >= 0 {
					for advance = 0; advance < k && i - advance >= 0; advance++ {
						if field[i - advance][j] != -1 {
							field[i - advance][j] += 1
							if max < field[i - advance][j] {
								max = field[i - advance][j]
								rowMax = i - advance
								colMax = j
							}
						} else {
							// backtrack
							for back = advance - 1; back >= 0; back-- {
								field[i - back][j] -= 1
								if rowMax == i - back && colMax == j {
									max -= 1
								}
							}
							break
						}
					}
				}
				// left
				if j - (k - 1) >= 0 {
					for advance = 0; advance < k && j - advance >= 0; advance++ {
						if field[i][j - advance] != -1 {
							field[i][j - advance] += 1
							if max < field[i][j - advance] {
								max = field[i][j - advance]
								rowMax = i
								colMax = j - advance
							}
						} else {
							// backtrack
							for back = advance - 1; back >= 0; back-- {
								field[i][j - back] -= 1
								if rowMax == i && colMax == j - back {
									max -= 1
								}
							}
							break
						}
					}
				}
			default:
			}
		}
	}

	fmt.Println(rowMax + 1, colMax + 1)
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	var str [105]string
	var cnt [105][105]int

	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&str[i])
	}

	res := 0
	resx, resy := 1, 1

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

			if str[i][j] == '.' && j + k - 1 < n {
				for r := j; r < j + k; r++ {
					cnt[i][r]++
					if str[i][r] != '.' {
						for rr := r; rr >= j; rr-- {
							cnt[i][rr]--
						}
						break
					}
				}
			}

			if str[i][j] == '.' && i + k - 1 < n {
				for r := i; r < i + k; r++ {
					cnt[r][j]++
					if str[r][j] != '.' {
						for rr := r; rr >= i; rr-- {
							cnt[rr][j]--
						}
						break
					}
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if cnt[i][j] > res {
				res = cnt[i][j]
				resx = i + 1
				resy = j + 1
			}
		}
	}
	fmt.Println(resx, resy)

}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	var str [105]string
	var cnt [105][105]int

	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&str[i])
	}

	res := 0
	resx, resy := 0, 0

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

			if str[i][j] == '.' && j + k - 1 < n {
				for r := j; r < j + k; r++ {
					cnt[i][r]++
					if str[i][r] != '.' {
						for rr := r; rr >= j; rr-- {
							cnt[i][rr]--
						}
						break
					}
				}
			}

			if str[i][j] == '.' && i + k - 1 < n {
				for r := i; r < i + k; r++ {
					cnt[r][j]++
					if str[r][j] != '.' {
						for rr := r; rr >= i; rr-- {
							cnt[rr][j]--
						}
						break
					}
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if cnt[i][j] > res {
				res = cnt[i][j]
				resx = i + 1
				resy = j + 1
			}
		}
	}
	fmt.Println(resx, resy)

}


package main

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

/* solution */

func solve() {

	n, d, e := readInt64(), readInt64(), readInt64()*5

	absoluteMin := n % gcd(d, e)

	var min int64 = 1000000000
	for i := int64(0); i <= n/d; i++ {
		cur := (n - i*d) % e
		if cur < min {
			min = cur
		}
		if min == absoluteMin {
			break
		}
	}

	printInt64(min)

}

func gcd(a, b int64) int64 {
	if a > b {
		a, b = b, a
	}
	if a == 1 {
		return int64(1)
	}
	if a == 0 {
		return b
	}
	return gcd(a, b%a)
}

/* 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 printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

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

package main

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

func main() {

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

	var n, d, e, resp int64

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

	e *= 5

	resp = 99999;
	for i := 0; i < 1000; i++ {
		nn := n
		if ((nn / e) - int64(i)) >= 0 {
			nn -= ((nn / e) - int64(i)) * e
		}
		nn -= (nn / d) * d
		if nn < resp {
			resp = nn
		}
	}

	fmt.Println(resp)

}

package main

import (
	"fmt"
	"math"
)

func main() {
	var totalRb, d, e int
	fmt.Scanf("%d\n", &totalRb)
	fmt.Scanf("%d\n", &d)
	fmt.Scanf("%d\n", &e)
	e = e * 5 //The minimal of a single euro
	packSum := e + d
	var less = totalRb
	var min = math.MaxInt32
	for less > 0 {
		min = intMin(min, intMin(safeMod(less, e), safeMod(less, d)))
		less -= packSum
	}
	fmt.Print(min)
	return
}

func safeMod(less, s int) int {
	if less < s {
		return less
	}
	return less % s
}

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

package main

import (
	"fmt"
)

func main() {
	var n, d, e int
	fmt.Scan(&n, &d, &e)
	e *= 5
	ans := 0x3f3f3f3f
	for i := n / d; i >= 0; i-- {
		j := (n - i*d) / e
		left := n - i*d - j*e
		if ans > left {
			ans = left
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	n, d, e := 0, 0, 0
	fmt.Scanf("%d\n%d\n%d", &n, &d, &e);
	e *= 5;

	ans := n;
	for i := 0; i * d <= n; i++ {
		update := n - i * d;
		j := update / e;
		update -= j * e;
		if update < ans {
			ans = update;
		}
	}
	fmt.Printf("%d\n", ans);
}

package main

import (
	"fmt"
)

func main() {
	var n, d, e int
	fmt.Scan(&n, &d, &e)
	ans := 1 << 30
	for i := 0; i <= n; i = i + e*5 {
		nn := (n - i) % d
		if nn < ans {
			ans = nn
		}
	}
	fmt.Println(ans)
}

package main

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

func lcm(a, b int) int {
	d := gcd(a, b)
	return a / d * b
}

func main() {
	defer Flush()
	n := readi()
	d := readi()
	e := readi() * 5

	ans := n
	for i := 0; i*d <= n; i++ {
		ans = min(ans, (n-i*d)%e)
	}
	println(ans)
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

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

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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

package main

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

func lcm(a, b int) int {
	d := gcd(a, b)
	return a / d * b
}

func main() {
	defer Flush()
	n := readi()
	d := readi()
	e := readi()
	dollar := []int{1, 2, 5, 10, 20, 50, 100}
	euro := []int{5, 10, 20, 50, 100, 200}

	l := lcm(d*100, e*200)
	n %= l

	a := make([]bool, l+100)
	a[0] = true
	for _, v := range dollar {
		for i := range a {
			if a[i] && i+v*d < len(a) {
				a[i+v*d] = true
			}
		}
	}
	for _, v := range euro {
		for i := range a {
			if a[i] && i+v*e < len(a) {
				a[i+v*e] = true
			}
		}
	}

	for i := n; 0 <= i; i-- {
		if a[i] {
			println(n - i)
			return
		}
	}

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

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

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var totalRb, d, e int
	fmt.Scanf("%d\n", &totalRb)
	fmt.Scanf("%d\n", &d)
	fmt.Scanf("%d\n", &e)
	e = e * 5 //The minimal of a single euro
	minMu := e + d
	var less int
	if totalRb < minMu {
		less = totalRb
	} else {
		less = totalRb % minMu
	}
	var dmin, emin int
	if less < d {
		dmin = less
	} else {
		dmin = less % d
	}

	if less < e {
		emin = less
	} else {
		emin = less % e
	}
	if dmin <= emin {
		fmt.Print(dmin)
	} else {
		fmt.Print(emin)
	}
	return
}

package main

import (
	"fmt"
)

func main() {
	var totalRb, d, e int
	fmt.Scanf("%d\n", &totalRb)
	fmt.Scanf("%d\n", &d)
	fmt.Scanf("%d\n", &e)
	e = e * 5 //The minimal of a single euro
	storeMin := make([]int, 0)
	if totalRb > d {
		storeMin = append(storeMin, totalRb%d)
	}
	if totalRb > e {
		storeMin = append(storeMin, totalRb%e)
	}

	minMu := e + d
	var less int
	if totalRb < minMu {
		less = totalRb
	} else {
		less = totalRb % minMu
	}
	var dmin, emin int
	if less < d {
		dmin = less
	} else {
		dmin = less % d
	}

	if less < e {
		emin = less
	} else {
		emin = less % e
	}
	storeMin = append(storeMin, emin)
	storeMin = append(storeMin, dmin)
	var result int = storeMin[0]
	for i := range storeMin {
		if storeMin[i] < result {
			result = storeMin[i]
		}
	}
	fmt.Print(result)

	return
}

package main

import (
	"fmt"
)

func main() {
	var n, d, e int
	fmt.Scan(&n, &d, &e)
	a := []int{0, 1, 2, 5, 10, 20, 50, 100}
	b := []int{0, 5, 10, 20, 50, 100, 200}
	ans := 0x3f3f3f3f
	for _, i := range a {
		for _, j := range b {
			left := n - d*i - e*j
			if left >= 0 && left < ans {
				ans = left
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, d, e int
	fmt.Scan(&n, &d, &e)
	a := n % (e * 5) % d
	b := n % d
	if a < b {
		fmt.Println(a)
	} else {
		fmt.Println(b)
	}
}

package main

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

func lcm(a, b int) int {
	d := gcd(a, b)
	return a / d * b
}

func main() {
	defer Flush()
	n := readi()
	d := readi()
	e := readi() * 5

	l := lcm(d, e)
	n %= l

	a := make([]bool, l+1)
	a[0] = true
	for _, v := range []int{d, e, d, e} {
		for i := range a {
			if a[i] && i+v < len(a) {
				a[i+v] = true
			}
		}
	}

	for i := n; 0 <= i; i-- {
		if a[i] {
			println(n - i)
			return
		}
	}

}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

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

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

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

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

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

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

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

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

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

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

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

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

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

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