Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas). Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, s1 anf s2, consisting of uppercase English letters. Then the boy makes string sk, using a recurrent equation sn = sn - 2 + sn - 1, operation '+' means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string sk on a piece of paper, puts it in the envelope and sends in to Santa. Vasya is absolutely sure that Santa will bring him the best present if the resulting string sk has exactly x occurrences of substring AC (the short-cut reminds him оf accepted problems). Besides, Vasya decided that string s1 should have length n, and string s2 should have length m. Vasya hasn't decided anything else.At the moment Vasya's got urgent New Year business, so he asks you to choose two strings for him, s1 and s2 in the required manner. Help Vasya.

The first line contains four integers k, x, n, m (3 ≤ k ≤ 50; 0 ≤ x ≤ 109; 1 ≤ n, m ≤ 100).

In the first line print string s1, consisting of n uppercase English letters. In the second line print string s2, consisting of m uppercase English letters. If there are multiple valid strings, print any of them. If the required pair of strings doesn't exist, print "Happy new year!" without the quotes.

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k, x, n, m int64
	fmt.Scan(&k, &x, &n, &m)
	var fa, fb int64 = 1, 1
	for i := int64(3); i < k; i++ {
		fa, fb = fb, fa+fb
	}
	var fbb, fx int64 = 0, 1
	for i := int64(4); i < k; i++ {
		fbb, fx = fx, fbb+fx+i%2
	}
	for s1 := int64(0); s1 <= n/2; s1++ {
		for s2 := int64(0); s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2)))
				fmt.Println(strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2)))
				return
			}
			if m-s2*2 > 1 {
				if s1*fa+s2*fb+fbb == x {
					fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2)))
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 1 {
				if (s1+1*fa)-k%2+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)))
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-1)))
					return
				} else if (s1+1)*fa-k%2+s2*fb == x {
					fmt.Println("C" + strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)))
					fmt.Println(strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-1)) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 1 {
				if (s1+1)*fa+s2*fb+fbb == x {
					fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-k%2+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-2)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

// A B AB BAB ABBAB BABABBAB ABBABBABABBAB BABABBABABBABBABABBAB ABBABBABABBABBABABBABABBABBABABBAB BABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB ABBABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBAB
// 1 1 3 4 8 12 21
// AZA
// CA
// AZACA
// CAAZACA
// AZACACAAZACA
// CAAZACAAZACACAAZACA

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k, x, n, m int64
	fmt.Scan(&k, &x, &n, &m)
	var fa, fb int64 = 1, 1
	for i := int64(3); i < k; i++ {
		fa, fb = fb, fa+fb
	}
	var fbb, fx int64 = 0, 1
	for i := int64(4); i < k; i++ {
		fbb, fx = fx, fbb+fx+i%2
	}
	for s1 := int64(0); s1 <= n/2; s1++ {
		for s2 := int64(0); s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2)))
				fmt.Println(strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2)))
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-1)))
					return
				} else if (s1+1)*fa-k%2+s2*fb == x {
					fmt.Println("C" + strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)))
					fmt.Println(strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-1)) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 1 {
				if (s1+1)*fa+s2*fb+fbb == x {
					fmt.Println(strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-1)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-k%2+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", int(s1)) + strings.Repeat("B", int(n-s1*2-2)) + "A")
					fmt.Println("C" + strings.Repeat("AC", int(s2)) + strings.Repeat("B", int(m-s2*2-2)) + "A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fbb, fx, fa, fb := 0, 0, 1, 1
	for i := 3; i < k; i++ {
		fbb, fx, fa, fb = fx, fa, fb, fa+fb
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2))
				fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2))
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1))
					return
				} else if (s1+1)*fa-k%2+s2*fb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1))
					fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 1 {
				if (s1+1)*fa+s2*fb+fbb == x {
					fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-2) + "A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-k%2+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-2) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-2) + "A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fbb, fa, fb := 0, 1, 1
	for k > 3 {
		fbb, fa, fb = fa, fb, fa+fb
		k--
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2))
				fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2))
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1))
					return
				} else if (s1+1)*fa-1+s2*fb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1))
					fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1) + "A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-1+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-2) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-2) + "A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

package main

import (
	"fmt"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fa, fb := 1, 1
	for k > 3 {
		fa, fb = fa, fa+fb
		k--
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				i := ac(s1)
				for i < n {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				i = ac(s2)
				for i < m {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if 2*s1*fa+s2*fb == x {
					i := ac(s1)
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					return
				} else if (2*s1-1)*fa+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					i = ac(s2)
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (3*s1-1)*fa+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

func ac(n int) int {
	for i := 0; i < n; i++ {
		fmt.Print("AC")
	}
	return 2 * n
}

// A B AB ABB ABBAB ABBABABB ABBABABBABBAB ABBABABBABBABABBABABB ABBABABBABBABABBABABBABBABABBABBAB
// f_k*x + f_{k+1}*y

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fa, fb := 1, 1
	for i := 3; i < k; i++ {
		fa, fb = fb, fa+fb
	}
	fbb, fx := 0, 1
	for i := 4; i < k; i++ {
		fbb, fx = fx, fbb+fx+i%2
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2))
				fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2))
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1))
					return
				} else if (s1+1)*fa-k%2+s2*fb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1))
					fmt.Println(strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-1) + "A")
					return
				}
			}
			if n-s1*2 > 0 && m-s2*2 > 1 {
				if (s1+1)*fa+s2*fb+fbb == x {
					fmt.Println(strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-1) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-2) + "A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-k%2+s2*fb+fbb == x {
					fmt.Println("C" + strings.Repeat("AC", s1) + strings.Repeat("B", n-s1*2-2) + "A")
					fmt.Println("C" + strings.Repeat("AC", s2) + strings.Repeat("B", m-s2*2-2) + "A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

package main

import (
	"fmt"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fa, fb := 1, 1
	for k > 3 {
		fa, fb = fb, fa+fb
		k--
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				i := ac(s1)
				for i < n {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				i = ac(s2)
				for i < m {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					i := ac(s1)
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					return
				} else if (s1+1)*fa-1+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					i = ac(s2)
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-1+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

func ac(n int) int {
	for i := 0; i < n; i++ {
		fmt.Print("AC")
	}
	return 2 * n
}

package main

import (
	"fmt"
)

func main() {
	var k, x, n, m int
	fmt.Scan(&k, &x, &n, &m)
	fa, fb := 1, 1
	for k > 3 {
		fa, fb = fa, fa+fb
		k--
	}
	for s1 := 0; s1 <= n/2; s1++ {
		for s2 := 0; s2 <= m/2; s2++ {
			if s1*fa+s2*fb == x {
				i := ac(s1)
				for i < n {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				i = ac(s2)
				for i < m {
					fmt.Print("B")
					i++
				}
				fmt.Println()
				return
			}
			if n-s1*2 > 0 && m-s2*2 > 0 {
				if (s1+1)*fa+s2*fb == x {
					i := ac(s1)
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					return
				} else if (s1+1)*fa-1+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n {
						fmt.Print("B")
						i++
					}
					fmt.Println()
					i = ac(s2)
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
			if n-s1*2 > 1 && m-s2*2 > 1 {
				if (s1+2)*fa-1+s2*fb == x {
					fmt.Print("C")
					i := ac(s1) + 1
					for i < n-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					fmt.Print("C")
					i = ac(s2) + 1
					for i < m-1 {
						fmt.Print("B")
						i++
					}
					fmt.Println("A")
					return
				}
			}
		}
	}
	fmt.Println("Happy new year!")
}

func ac(n int) int {
	for i := 0; i < n; i++ {
		fmt.Print("AC")
	}
	return 2 * n
}

// A B AB ABB ABBAB ABBABABB ABBABABBABBAB ABBABABBABBABABBABABB ABBABABBABBABABBABABBABBABABBABBAB
// f_k*x + f_{k+1}*y


CQXYM wants to create a connected undirected graph with $$$n$$$ nodes and $$$m$$$ edges, and the diameter of the graph must be strictly less than $$$k-1$$$. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one edge).The diameter of a graph is the maximum distance between any two nodes.The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.CQXYM wonders whether it is possible to create such a graph.

The input consists of multiple test cases.  The first line contains an integer $$$t (1 \leq t \leq 10^5)$$$ — the number of test cases. The description of the test cases follows. Only one line of each test case contains three integers $$$n(1 \leq n \leq 10^9)$$$, $$$m$$$, $$$k$$$ $$$(0 \leq m,k \leq 10^9)$$$.

For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).

NoteIn the first test case, the graph's diameter equal to 0.In the second test case, the graph's diameter can only be 2.In the third test case, the graph's diameter can only be 1.

package main

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

var n, m, k int64

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}
	if m > n * (n - 1)/2 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}

	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == (n * (n - 1))/2 {
			return "YES"
		}
		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

func solve(n int64, m int64, k int) string {
	max := int64(n * (n - 1) / 2)
	if n == 1 {
		if k > 1 {
			return "YES"
		} else {
			return "NO"
		}
	} else if m < max {
		if k > 3 {
			return "YES"
		} else {
			return "NO"
		}
	} else if k > 2 {
		return "YES"
	} else {
		return "NO"
	}
}
func CF1581B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var k int
	var n, m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n * (n - 1) / 2)
		if m > max || m < n-1 {
			Fprintln(out, "NO")
			continue
		}
		// Fprintln(out, solve(n, m, k))
		switch k {
		// Fprintln(out, "NO")
		case 0, 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

func solve(n int64, m int64, k int) string {
	max := int64(n*(n-1)) >> 1
	if n == 1 {
		if k > 1 {
			return "YES"
		} else {
			return "NO"
		}
	} else if m < max {
		if k > 3 {
			return "YES"
		} else {
			return "NO"
		}
	} else if k > 2 {
		return "YES"
	} else {
		return "NO"
	}
}
func CF1581B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var k int
	var n, m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n * (n - 1) / 2)
		if m > max || m < n-1 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, solve(n, m, k))
		//     switch k {
		//     case 0:
		//     case 1:
		//         Fprintln(out, "NO")
		//     case 2:
		//         if n == 1 {
		//             Fprintln(out, "YES")
		//         } else {
		//             Fprintln(out, "NO")
		//         }
		//     case 3:
		//         if m == max {
		//             Fprintln(out, "YES")
		//         } else {
		//             Fprintln(out, "NO")
		//         }
		//     default:
		//         Fprintln(out, "YES")
		//     }
	}
}

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

package main

import (
	"bufio"
	"os"
)

func main() {
	var t int64
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	read_int64 := func() (x int64) {
		c, _ := in.ReadByte()
		for ; c < '0'; c, _ = in.ReadByte() {
		}
		for ; c >= '0'; c, _ = in.ReadByte() {
			x = x*10 + int64(c-'0')
		}
		return
	}
	t = read_int64()
	for ; t > 0; t-- {
		var n, m, k int64
		ans := false
		n = read_int64()
		m = read_int64()
		k = read_int64()
		if 1 == n {
			if k >= 2 && 0 == m {
				ans = true
			}
		} else if 3 == k {
			if m == n*(n-1)/2 {
				ans = true
			}
		} else if k >= 4 {
			if m >= n-1 && m <= n*(n-1)/2 {
				ans = true
			}
		}
		if ans {
			out.WriteString("YES\n")
		} else {
			out.WriteString("NO\n")
		}
	}
}

package main

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

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

	var T, k int
	var n, m int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		if m < n-1 || m > n*(n-1)/2 {
			Fprintln(out, "NO")
			continue
		}
		d := 0
		if n > 1 {
			if m == n*(n-1)/2 {
				d = 1
			} else {
				d = 2
			}
		}
		if d < k-1 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

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

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

var t int

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

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

		var n, m, k int64
		fmt.Fscan(input, &n, &m, &k)

		// ARRAY := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARRAY[i])

		// }

		// String := make([]byte, 0)
		// fmt.Fscan(input, &String)

		if m < n-1 || m > n*(n-1)/2 {
			fmt.Println("NO")
		} else {
			if k <= 1 {
				fmt.Println("NO")
			} else {
				if k == 2 {
					if n == 1 {
						fmt.Println("YES")
					} else {
						fmt.Println("NO")
					}
				} else {
					if k == 3 {
						if m == n*(n-1)/2 {
							fmt.Println("YES")
						} else {
							fmt.Println("NO")
						}
					} else {
						fmt.Println("YES")
					}
				}
			}

		}

	}

}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}
func testcase() {
	n := iost.GetNextInt64()
	m := iost.GetNextInt64()
	k := iost.GetNextInt64()
	if m+1 < n {
		iost.Println("NO")
		return
	}
	if m > n*(n-1)/2 {
		iost.Println("NO")
		return
	}
	switch k {
	case 0, 1:
		iost.Println("NO")
	case 2:
		if n == 1 {
			iost.Println("YES")
			return
		}
		iost.Println("NO")
	case 3:
		if m == n*(n-1)/2 {
			iost.Println("YES")
			return
		}
		iost.Println("NO")
	default:
		iost.Println("YES")
	}

}

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}
	if m > n * (n - 1)/2 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}

	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == (n * (n - 1))/2 {
			return "YES"
		}
		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}
	if m > n * (n - 1)/2 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}

	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == (n * (n - 1))/2 {
			return "YES"
		}
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}
	if m > n * (n - 1)/2 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if m == (n * (n - 1))/2 {
		if k >= 3 {
			return "YES"
		}
		return "NO"
	}

	if k > 3 {
		return "YES"
	}

	return "NO"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}
	if m > n * (n - 1)/2 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k >= 3 {
		if m == (n * (n - 1))/2 {
			return "YES"
		}

		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == (n * (n - 1))/2 {
			return "YES"
		}

		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == n * (n - 1)/2 {
			return "YES"
		}
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if k == 3 {
		if m == n * (n - 1)/2 {
			return "YES"
		}
		return "NO"
	}

	return "YES"

}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 {
		return "NO"
	}
	if k == 2 {
		if n == 1 {
			return "YES"
		}
		return "NO"
	}

	if m == (n * (n - 1))/2 {
		if k >= 3 {
			return "YES"
		}
		return "NO"
	}

	if k >= 4 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 || k == 2{
		return "NO"
	}

	if m == n * (n - 1)/2 {
		if k >= 3 {
			return "YES"
		}
		return "NO"
	}

	if k - 1 >=3 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1 || k == 2{
		return "NO"
	}

	if m == n * (n - 1)/2 {
		if k - 1 >= 1 {
			return "YES"
		}
		return "NO"
	}

	if k - 1 >=3 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 || k == 1{
		return "NO"
	}
	if k == 2 {
		if m == 0 {
			return "YES"
		}
		return "NO"
	}

	if m == n * (n - 1)/2 {
		if k - 1 >= 1 {
			return "YES"
		}
		return "NO"
	}

	if k - 1 >=3 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if k == 0 {
		return "NO"
	}
	if k == 1 {
		if m == 0 {
			return "YES"
		}
		return "NO"
	}

	if m == n * (n - 1)/2 {
		if k - 1 >= 1 {
			return "YES"
		}
		return "NO"
	}

	if k - 1 >=3 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

var n, m, k int

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &m, &k)

		fmt.Println(solve())
	}
}

func solve() string {
	if m < n - 1 {
		return "NO"
	}

	if m == n * (n - 1)/2 {
		if k - 1 >= 1 {
			return "YES"
		}
		return "NO"
	}

	if k - 1 >=3 {
		return "YES"
	}
	return "NO"
}

// k = 3,  d < 2, k >= 4

package main

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

func solve(n int64, m int64, k int) string {
	max := int64(n * (n - 1) / 2)
	if n == 1 {
		if k > 1 {
			return "YES"
		} else {
			return "NO"
		}
	} else if m < max {
		if k > 3 {
			return "YES"
		} else {
			return "NO"
		}
	} else if k > 2 {
		return "YES"
	} else {
		return "NO"
	}
}
func CF1581B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var k int
	var n, m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n * (n - 1) / 2)
		if m > max || m < n-1 {
			Fprintln(out, "NO")
			continue
		}
		// Fprintln(out, solve(n, m, k))
		switch k {
		case 0:
		case 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

func solve(n int, m int64, k int) string {
	max := int64(n*(n-1)) >> 1
	if n == 1 {
		if k > 1 {
			return "YES"
		} else {
			return "NO"
		}
	} else if m < max {
		if k > 3 {
			return "YES"
		} else {
			return "NO"
		}
	} else if k > 2 {
		return "YES"
	} else {
		return "NO"
	}
}
func CF1581B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, k int
	var m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n*(n-1)) >> 1
		if m > max || m < int64(n-1) {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, solve(n, m, k))
		//     switch k {
		//     case 0:
		//     case 1:
		//         Fprintln(out, "NO")
		//     case 2:
		//         if n == 1 {
		//             Fprintln(out, "YES")
		//         } else {
		//             Fprintln(out, "NO")
		//         }
		//     case 3:
		//         if m == max {
		//             Fprintln(out, "YES")
		//         } else {
		//             Fprintln(out, "NO")
		//         }
		//     default:
		//         Fprintln(out, "YES")
		//     }
	}
}

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

package main

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

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

	var t int
	var n, k int
	var m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n*(n-1)) >> 1
		if m > max || m < int64(n-1) {
			Fprintln(out, "NO")
			continue
		}
		switch k {
		case 0:
		case 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

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

	var t int
	var n, k int
	var m int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := int64(n) * int64((n-1)>>1)
		if m > max || m < int64(n-1) {
			Fprintln(out, "NO")
			continue
		}
		switch k {
		case 0:
		case 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

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

	var t int
	var n, m, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := (n * (n - 1)) >> 1
		if m > max || m < n-1 {
			Fprintln(out, "NO")
			continue
		}
		switch k {
		case 0:
		case 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

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

	var t int
	var n, m, k int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &k)
		max := (n * (n - 1)) >> 1
		if m > max {
			Fprintln(out, "NO")
			continue
		}
		switch k {
		case 0:
		case 1:
			Fprintln(out, "NO")
		case 2:
			if n == 1 {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		case 3:
			if m == max {
				Fprintln(out, "YES")
			} else {
				Fprintln(out, "NO")
			}
		default:
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	read_int := func() (x int) {
		c, _ := in.ReadByte()
		for ; c < '0'; c, _ = in.ReadByte() {
		}
		for ; c >= '0'; c, _ = in.ReadByte() {
			x = x*10 + int(c-'0')
		}
		return
	}
	t = read_int()
	for ; t > 0; t-- {
		var n, m, k int
		ans := false
		n = read_int()
		m = read_int()
		k = read_int()
		if 1 == n {
			if k >= 2 && 0 == m {
				ans = true
			}
		} else if 3 == k {
			if m == n*(n-1)/2 {
				ans = true
			}
		} else if k >= 4 {
			if m >= n-1 && m <= n*(n-1)/2 {
				ans = true
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	read_int := func() (x int) {
		c, _ := in.ReadByte()
		for ; c < '0'; c, _ = in.ReadByte() {
		}
		for ; c >= '0'; c, _ = in.ReadByte() {
			x = x*10 + int(c-'0')
		}
		return
	}
	t = read_int()
	for ; t > 0; t-- {
		var n, m, k int
		ans := false
		n = read_int()
		m = read_int()
		k = read_int()
		if 1 == n {
			if k >= 2 {
				ans = true
			}
		} else if 3 == k {
			if m == n*(n-1)/2 {
				ans = true
			}
		} else if k >= 4 {
			if m >= n-1 && m <= n*(n-1)/2 {
				ans = true
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


This is an interactive problem.We have hidden an integer $$$1 \le X \le 10^{9}$$$. You don't have to guess this number. You have to find the number of divisors of this number, and you don't even have to find the exact number: your answer will be considered correct if its absolute error is not greater than 7 or its relative error is not greater than $$$0.5$$$. More formally, let your answer be $$$ans$$$ and the number of divisors of $$$X$$$ be $$$d$$$, then your answer will be considered correct if at least one of the two following conditions is true: $$$| ans - d | \le 7$$$; $$$\frac{1}{2} \le \frac{ans}{d} \le 2$$$.You can make at most $$$22$$$ queries. One query consists of one integer $$$1 \le Q \le 10^{18}$$$. In response, you will get $$$gcd(X, Q)$$$ — the greatest common divisor of $$$X$$$ and $$$Q$$$.The number $$$X$$$ is fixed before all queries. In other words, interactor is not adaptive.Let's call the process of guessing the number of divisors of number $$$X$$$ a game. In one test you will have to play $$$T$$$ independent games, that is, guess the number of divisors $$$T$$$ times for $$$T$$$ independent values of $$$X$$$.

The first line of input contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of games.

NoteWhy the limitation for number of queries is 22 exactly? Maybe the problem author is a Taylor Swift fan.Let's look at the example.In the first game $$$X = 998\,244\,353$$$ is hidden. Would be hard to guess this, right? This number is prime, so the number of its divisors is 2. The solution has made several random queries, and all the responses turned out to be 1 (strange things, not even one of three random numbers is divisible by $$$998\,244\,353$$$). It's fare to assume that the hidden number doesn't have many divisors, so the solution has answered 5. Why not. This answer will be considered correct since $$$| 5 - 2 | = 3 \le 7$$$.In the second game $$$X = 4\,194\,304 = 2^{22}$$$ is hidden, it has 23 divisors. The solution has made queries $$$1024 = 2^{10}$$$, $$$1\,048\,576 =2^{20}$$$, $$$1\,073\,741\,824 = 2^{30}$$$ and got responses $$$1024 = 2^{10}$$$, $$$1\,048\,576 =2^{20}$$$, $$$4\,194\,304 = 2^{22}$$$, respectively. Then the solution got completely confused and answered the answer to The Ultimate Question of Life, the Universe, and Everything. This answer will be considered correct since $$$\frac{1}{2} \le \frac{42}{23} \le 2$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1355F() {
	const mx int = 1e3
	primes := []int{}
	isP := [mx]bool{}
	for i := range isP {
		isP[i] = true
	}
	isP[0], isP[1] = false, false
	for i := 2; i < mx; i++ {
		if isP[i] {
			primes = append(primes, i)
			for j := 2 * i; j < mx; j += i {
				isP[j] = false
			}
		}
	}
	upper := big.NewInt(1e18)

	var t int
	var g int64
	for Scan(&t); t > 0; t-- {
		ans := 1
		es := [mx]int{}
		for i := 0; i < 22; i++ {
			checks := []int64{}
			q := big.NewInt(1)
		o:
			for _, p := range primes {
				if e := es[p]; e >= 0 {
					for ; e >= 0; e-- {
						p := big.NewInt(int64(p))
						if new(big.Int).Mul(q, p).Cmp(upper) > 0 {
							break o
						}
						q.Mul(q, p)
					}
					checks = append(checks, int64(p))
				}
			}
			Println("?", q.Int64())
			Scan(&g)
			for _, p := range checks {
				e := 0
				for ; g%p == 0; g /= p {
					e++
				}
				if e > es[p] {
					es[p] = e
					if i == 21 {
						ans *= e + 1
					}
				} else {
					es[p] = -1
					ans *= e + 1
				}
			}
		}
		ans *= 2
		if ans < 8 {
			ans = 8
		}
		Println("!", ans)
	}
}

func main() { CF1355F() }

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	const mx = 1e3
	ps := []int{}
	v := [mx]bool{}
	for i := 2; i < mx; i++ {
		if !v[i] {
			ps = append(ps, i)
			for j := 2 * i; j < mx; j += i {
				v[j] = true
			}
		}
	}
	upper := NewInt(1e18)

	var t int
	var g int64
	for Scan(&t); t > 0; t-- {
		ans := 1
		es := [mx]int{}
		for i := 0; i < 22; i++ {
			checks := []int64{}
			q := NewInt(1)
		o:
			for _, p := range ps {
				if e := es[p]; e >= 0 {
					for ; e >= 0; e-- {
						p := NewInt(int64(p))
						if new(Int).Mul(q, p).Cmp(upper) > 0 {
							break o
						}
						q.Mul(q, p)
					}
					checks = append(checks, int64(p))
				}
			}
			Println("?", q.Int64())
			Scan(&g)
			for _, p := range checks {
				e := 0
				for ; g%p == 0; g /= p {
					e++
				}
				if e > es[p] {
					es[p] = e
					if i == 21 {
						ans *= e + 1
					}
				} else {
					es[p] = -1
					ans *= e + 1
				}
			}
		}
		ans *= 2
		if ans < 8 {
			ans = 8
		}
		Println("!", ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	const mx int = 1e3
	ps := []int{}
	isP := [mx]bool{}
	for i := range isP {
		isP[i] = true
	}
	isP[0], isP[1] = false, false
	for i := 2; i < mx; i++ {
		if isP[i] {
			ps = append(ps, i)
			for j := 2 * i; j < mx; j += i {
				isP[j] = false
			}
		}
	}
	upper := big.NewInt(1e18)

	var t int
	var g int64
	for Scan(&t); t > 0; t-- {
		ans := 1
		es := [mx]int{}
		for i := 0; i < 22; i++ {
			checks := []int64{}
			q := big.NewInt(1)
		o:
			for _, p := range ps {
				if e := es[p]; e >= 0 {
					for ; e >= 0; e-- {
						p := big.NewInt(int64(p))
						if new(big.Int).Mul(q, p).Cmp(upper) > 0 {
							break o
						}
						q.Mul(q, p)
					}
					checks = append(checks, int64(p))
				}
			}
			Println("?", q.Int64())
			Scan(&g)
			for _, p := range checks {
				e := 0
				for ; g%p == 0; g /= p {
					e++
				}
				if e > es[p] {
					es[p] = e
					if i == 21 {
						ans *= e + 1
					}
				} else {
					es[p] = -1
					ans *= e + 1
				}
			}
		}
		ans *= 2
		if ans < 8 {
			ans = 8
		}
		Println("!", ans)
	}
}


You are given three positive integers $$$n$$$, $$$a$$$ and $$$b$$$. You have to construct a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters such that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.Recall that the substring $$$s[l \dots r]$$$ is the string $$$s_l, s_{l+1}, \dots, s_{r}$$$ and its length is $$$r - l + 1$$$. In this problem you are only interested in substrings of length $$$a$$$.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains three space-separated integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le a \le n \le 2000, 1 \le b \le \min(26, a)$$$), where $$$n$$$ is the length of the required string, $$$a$$$ is the length of a substring and $$$b$$$ is the required number of distinct letters in each substring of length $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer — such a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters that each substring of length $$$a$$$ has exactly $$$b$$$ distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

NoteIn the first test case of the example, consider all the substrings of length $$$5$$$:  "tleel": it contains $$$3$$$ distinct (unique) letters,  "leelt": it contains $$$3$$$ distinct (unique) letters,  "eelte": it contains $$$3$$$ distinct (unique) letters.

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, a, b int
		fmt.Fscan(in, &n, &a, &b)
		for i := 0; i < n; i++ {
			fmt.Fprint(out, string('a'+i%b))
		}
		fmt.Fprintln(out)
	}
}

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, a, b int
		fmt.Fscan(in, &n, &a, &b)
		for i := 0; i < n; i++ {
			if i%a < b {
				fmt.Fprint(out, string('a'+i%a))
			} else {
				fmt.Fprint(out, string('a'))
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

var letters = []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

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

func exec() {
	var n, a, b int
	scanf("%d %d %d\n", &n, &a, &b)

	j := 0
	k := 0
	for i := 0; i < n; i++ {
		if j == a {
			j = 0
			k = 0
		}
		printf("%s", string(letters[k]))
		j++
		if k != b-1 {
			k++
		}
	}
	printf("\n")
}

package main

import (
	"fmt"
	"os"
)

func main() {
	in, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = in
	}

	var t int
	fmt.Scan(&t)

	for ; t > 0; t-- {
		var n, a, b int
		fmt.Scan(&n, &a, &b)

		for i := 0; i < n; i++ {
			fmt.Printf("%c", 'a'+i%b)
		}
		fmt.Printf("\n")
	}
}

package main

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

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

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

	var t int
	var n, a, b int
	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n, &a, &b)
		var s strings.Builder
		alph := 'a'
		countUnique := 0
		strlen := 0
		for i := 0; i < n; i++ {
			if countUnique < b-1 {
				s.WriteString(string(alph))
				countUnique++
				strlen++
				alph++
			} else {
				for ; i < n && strlen < a; i++ {
					s.WriteString(string(alph))
					strlen++
				}
				break
			}
		}
		temp := s.String()
		for i := 0; i < n/a; i++ {
			s.WriteString(temp)
		}
		sol := s.String()
		Fprintln(out, sol[:n])
	}
}

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

package main

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

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

    var t, n, a, b int
    fmt.Fscan(in, &t)
    for ;t >0; t-- {
        fmt.Fscan(in, &n, &a, &b)
        var s strings.Builder
        for i := 0; i < n; i++ {
            s.WriteRune(rune('a' + i%b))
        }
        fmt.Fprintln(out, s.String())
    }
}

package main

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

func solve(n int, a int, b int) string {
	firstLetter := byte('a')
	res := make([]byte, n)
	subStr := make([]byte, a)
	j := 0

	for i := range subStr {
		subStr[i] = (firstLetter + byte(j%b))
		j++
	}

	j = 0
	for i := range res {
		res[i] = subStr[j%a]
		j++
	}

	return string(res)
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var t, n, a, b int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d %d %d\n", &n, &a, &b)
		fmt.Fprintf(os.Stdout, "%s\n", solve(n, a, b))
	}
}

package main

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

const N = 2020
var nt, n, a, b int
var s[N] uint8

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for nt > 0 {
		nt--
		fmt.Fscanf(reader, "%d %d %d\n", &n, &a, &b)
		for i := 0; i < a; i++ {
			s[i] = uint8('a' + i % b)
		}
		for i := a; i < n; i++ {
			s[i] = s[i % a]
		}
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer,"%c", s[i])
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

import (
	"fmt"
)

func main() {
	alphbet:= [26]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	var t int
	fmt.Scan(&t)
	for j := 0; j < t; j++ {
		var n, a, b int
		fmt.Scan(&n, &a, &b)
		var k int
		k = 0
		var s string
		s = ""
		for i := 0; i < n; i++ {
			s += alphbet[k]
			if k < b-1 {
				k++
			} else {
				k = 0
			}
		}
		fmt.Println(s)
	}
}

package main

import (
	"bytes"
	"fmt"
)

func main() {
	var t, n, a, b int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &a, &b)
		var buf bytes.Buffer
		for j := 0; j < a; j++ {
			if j < b {
				buf.WriteByte(byte('a' + j))
			} else {
				buf.WriteByte('a')
			}
		}
		pattern := buf.String()
		for j := 0; j < (n-1)/a; j++ {
			buf.WriteString(pattern)
		}
		fmt.Println(buf.String()[0:n])
	}
}

package main

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

func repeater(num int64, rep []byte) string {
	result := make([]byte, num)
	copy(result, rep)
	for bp := len(rep); bp < len(result); bp *= 2 {
		copy(result[bp:], result[:bp])
	}
	return string(result)
}

func main() {
	var truncator string
	if runtime.GOOS == "windows" {
		truncator = "\r\n"
	} else {
		truncator = "\n"
	}
	lowercase := []byte("abcdefghijklmnopqrstuvwxyz")

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, truncator)
	testcase, _ := strconv.ParseInt(text, 10, 64)

	var i int64
	input := make([][]int64, testcase)
	result := make([]string, testcase)
	for i = 0; i < testcase; i++ {
		input[i] = readInt(3, reader)
		usinglower := lowercase[0:input[i][2]]
		result[i] = repeater(input[i][0], usinglower)
	}

	output := strings.Join(result, "\n")
	fmt.Printf("%s\n", output)
}

func readInt(size int, reader *bufio.Reader) []int64 {
	text, _ := reader.ReadString('\n')
	split := strings.Fields(text)
	result := make([]int64, len(split))
	for i := range result {
		result[i], _ = strconv.ParseInt(split[i], 10, 64)
	}
	return result
}

// Author: sighduck
// URL: https://codeforces.com/contest/1335/problem/B

package main

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

func Solve(n, a, b int) string {
	letters := "abcdefghijklmnopqrstuvwxyz"
	order := letters[:b]
	ans := make([]byte, n)
	for i := 0; i < n; i++ {
		ans[i] = order[i%b]
	}
	return string(ans)
}

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

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

package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.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 (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n, a, b := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
        writer.Printf("%s\n", sol(n, a, b))
    }
}

func sol(n, a, b int64) string {
    s := formString(a, b)
    ret := []byte{}
    ptr := 0
    for ; n > 0; n-- {
        ret = append(ret, s[ptr])
        ptr++
        if ptr == len(s) {
            ptr = 0
        }
    }
    return string(ret)
}

// 5, 3 => abccc
func formString(a, b int64) []byte {
    ret := []byte{}
    i := int64(0)
    for ; i < b; i++ {
        ret = append(ret, 'a' + byte(i))
    }
    i--
    for rem := a-b; rem > 0; rem-- {
        ret = append(ret, 'a' + byte(i))
    }
    return ret
}


Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors. Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

First line of input consists of one integer n (1 ≤ n ≤ 3000). Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output single integer — minimum amount of coins the colonel has to pay.

NoteIn first sample test we can increase factor of first badge by 1.In second sample test we can increase factors of the second and the third badge by 1.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	ans := 0
	for i := range a[1:] {
		if a[i] >= a[i+1] {
			ans += a[i] - a[i+1] + 1
			a[i+1] = a[i] + 1
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

const (
	MAX_N = 8000
)

var (
	n int
	a [MAX_N]int
)

func main() {
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		a[v]++
	}
	r := 0
	for i := 0; i < MAX_N - 1; i++ {
		if a[i] > 1 {
			v := a[i] - 1
			r += v
			a[i] -= v
			a[i + 1] += v
		}
	}
	fmt.Printf("%d\n", r)
}

package main
import (
	"fmt"
)
const(
	max=8000
)
var (
	j int
	a[8000] int
)
func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		a[j]++
	}
	s := 0
	for i := 0; i < 8000- 1; i++ {
		if a[i] > 1 {
			q:= a[i] - 1
			s += q
			a[i] -= q
			a[i + 1] += q
		}
	}
	fmt.Printf("%d\n", s)
}

package main

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

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

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

	n := nextInt()
	a := make([]int, 10000)
	coin, coolness := 0, 0

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

	for i := 1; i < 10000; i++ {
		coin += coolness

		if coolness > 0 {
			if a[i] == 0 {
				coolness -= 1
			}
		}

		if a[i] > 1 {
			coolness += a[i] - 1
		}
	}

	println(coin)
}

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

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

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

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

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

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

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  badges := make([]int, n)
  for i := range badges {
    badges[i] = getI()
  }
  sort.Ints(badges)
  peak := 0
  result := 0
  for _, badge := range badges {
    if badge > peak {
      peak = badge
    } else {
      peak++
      result += peak-badge
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var n, a, ans int
    var used [9999]int
    fmt.Fscan(scanner, &n)

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

    for i := 1; i <= n; i++ {
        for used[i] > 1 {
            j := i
            for used[j] > 0 {
                j++
                ans++
            }
            used[j]++
            used[i]--
        }
    }

    writer.WriteString(strconv.Itoa(ans))
    writer.Flush()
}

package main

import (
	"fmt"
)

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

	counts := make([]int, 2*n, 2*n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		counts[a]++
	}

	next := 1
	ans := 0
	for i := 1; i <= n; i++ {
		for counts[i] > 1 {
			counts[i]--
			for next <= i || counts[next] != 0 {
				next++
			}
			ans += next - i
			counts[next]++
		}
	}

	fmt.Println(ans)
}

package main

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

func main() {
	n := nextInt()
	cnt := make([]int, 2*n+100)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
		cnt[a[i]]++
	}
	ans := 0
	for i := range cnt {
		for cnt[i] > 1 {
			j := i
			for cnt[j] > 1 {
				cnt[j]--
				j++
				ans++
				cnt[j]++
			}
		}
	}
	fmt.Println(ans)
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

// cf569b project main.go
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	z := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&z[i])
	}
	sort.Ints(z)
	m := 0
	for i := 1; i < n; i++ {
		for ; z[i-1] >= z[i]; z[i]++ {
			m++
		}
	}
	fmt.Println(m)

}

package main
import (
	"fmt"
)
const(
	max=5000
)
var (
	j int
	a[5000] int
)
func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		a[j]++
	}
	s := 0
	for i := 0; i < 5000 - 1; i++ {
		if a[i] > 1 {
			q:= a[i] - 1
			s += q
			a[i] -= q
			a[i + 1] += q
		}
	}
	fmt.Printf("%d\n", s)
}

package main

import (
	"fmt"
)

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

	counts := make([]int, 2*n, 2*n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		counts[a]++
	}

	next := 1
	ans := 0
	for i := 1; i <= n; i++ {
		for counts[i] > 1 {
			counts[i]--
			for next <= i || counts[next] != 0 {
				next++
			}
			ans += next - i
		}
	}

	fmt.Println(ans)
}


SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will win the match.

Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

package main

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

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

type Fraction struct {
	delim int64
	denom int64
}

func GCD(p int64, q int64) int64 {
	if q == 0 {
		return p
	}
	return GCD(q, p%q)
}

func NewFraction(p int64, q int64) *Fraction {
	ans := new(Fraction)
	g := GCD(p, q)
	ans.delim = p / g
	ans.denom = q / g
	return ans
}

func (frac *Fraction) Add(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom+frac.denom*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Sub(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom-frac.denom*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Mul(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Div(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom,
		frac.denom*frac2.delim)
}

func (frac *Fraction) Reverse() *Fraction {
	return NewFraction(frac.denom, frac.delim)
}

func (frac *Fraction) Rational() float64 {
	return float64(frac.delim) / float64(frac.denom)
}

func main() {
	scanner.Split(bufio.ScanWords)
	p, q := NewFraction(int64(NextInt()), int64(NextInt())),
		NewFraction(int64(NextInt()), int64(NextInt()))
	ans := p.Div(p.Add(q).Sub(p.Mul(q))).Rational()
	w.WriteString(strconv.FormatFloat(ans, 'f', 7, 64))
	w.WriteByte('\n')
	w.Flush()
}

package main

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

func main() {
    var a,b,c,d,ans float64
    fmt.Scan(&a,&b,&c,&d)
    ans=(a*d)/((a*d)+(b*c)-(a*c))
    fmt.Println(ans)
}

//312B
package main
import "fmt"

func main() {
	var e, f, g, h, x float64
	fmt.Scan(&e, &f, &g, &h)
	x=(e*h)/(f*g + e*h - e*g)
	fmt.Printf("%.12f\n", x)
}

package main

import "fmt"

func main() {
    var a,b,c,d float64
    fmt.Scan(&a,&b,&c,&d)
    fmt.Println((a/b)/(1-((1-a/b)*(1-c/d))))
}

//312B
package main
import "fmt"

func main() {
    var e, f, g, h, x float64 // variabel e, f, g, h, x adlah float64
    fmt.Scan(&e, &f, &g, &h) // meminta input e, f, g, h
    x=(e*h)/(f*g + e*h - e*g) // perhitungannya
    fmt.Printf("%.12f\n", x) // mencetak output
}

// 312B
package main

import (
	"fmt"
)

func main() {
	var j, k, l, m float64
	fmt.Scan(&j, &k, &l, &m)
	fmt.Print((j * m) / (k*l + j*m - j*l))
}

package main

import (
	"fmt"
)

func solve(a, b, c, d float64) {
	p := a / b
	q := (1 - c/d) * (1 - a/b)

	fmt.Println(p / (1 - q))
}

func main() {
	var a, b, c, d float64

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	solve(a, b, c, d)
}

// 312B-mic
package main

import (
    "fmt"
)

func main() {
    var a, b, c, d float64
    fmt.Scan(&a, &b, &c, &d)
    p := a / b
    q := (1 - a/b) * (1 - c/d)
    res := p / (1 - q)
    fmt.Println(res)
}

package main

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

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

type Fraction struct {
	delim int
	denom int
}

func GCD(p int, q int) int {
	if q == 0 {
		return p
	}
	return GCD(q, p%q)
}

func NewFraction(p int, q int) *Fraction {
	ans := new(Fraction)
	g := GCD(p, q)
	ans.delim = p / g
	ans.denom = q / g
	return ans
}

func (frac *Fraction) Add(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom+frac.denom*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Sub(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom-frac.denom*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Mul(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Div(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom,
		frac.denom*frac2.delim)
}

func (frac *Fraction) Reverse() *Fraction {
	return NewFraction(frac.denom, frac.delim)
}

func (frac *Fraction) Round() int {
	return frac.delim / frac.denom
}

func (frac *Fraction) Rational() float64 {
	return float64(frac.delim) / float64(frac.denom)
}

func main() {
	scanner.Split(bufio.ScanWords)
	p, q := NewFraction(NextInt(), NextInt()),
		NewFraction(NextInt(), NextInt())
	ans := p.Div(p.Add(q).Sub(p.Mul(q))).Rational()
	w.WriteString(strconv.FormatFloat(ans, 'f', 7, 64))
	w.WriteByte('\n')
	//p/(1-(1-p)(1-q)) = p/(p+q-pq)
	w.Flush()
}

package main

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

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

type Fraction struct {
	delim int
	denom int
}

func GCD(p int, q int) int {
	if q == 0 {
		return p
	}
	return GCD(q, p%q)
}

func NewFraction(p int, q int) *Fraction {
	ans := new(Fraction)
	g := GCD(p, q)
	ans.delim = p / g
	ans.denom = q / g
	return ans
}

func (frac *Fraction) Sub(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.denom-frac.denom*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Mul(frac2 *Fraction) *Fraction {
	return NewFraction(frac.delim*frac2.delim,
		frac.denom*frac2.denom)
}

func (frac *Fraction) Reverse() *Fraction {
	return NewFraction(frac.denom, frac.delim)
}

func (frac *Fraction) Rational() float64 {
	return float64(frac.delim) / float64(frac.denom)
}

func main() {
	scanner.Split(bufio.ScanWords)
	p, q := NewFraction(NextInt(), NextInt()),
		NewFraction(NextInt(), NextInt())
	ans := p.Mul(NewFraction(1, 1).Sub(p.Mul(q)).Reverse()).Rational()
	w.WriteString(strconv.FormatFloat(ans, 'f', 7, 64))
	w.WriteByte('\n')
	w.Flush()
}

package main
import "fmt"

func main() {
	var e, f, g, h, x float64
	fmt.Scan(&e, &f, &g, &h)
	x=(f*g)/(f*g + e*h - e*g)
	fmt.Printf("%.12f\n", x)
}


Igor is in the museum and he wants to see as many pictures as possible.Museum can be represented as a rectangular field of n × m cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that share a side with the current one.For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will examine every picture he can see.

First line of the input contains three integers n, m and k (3 ≤ n, m ≤ 1000, 1 ≤ k ≤ min(n·m, 100 000)) — the museum dimensions and the number of starting positions to process. Each of the next n lines contains m symbols '.', '*' — the description of the museum. It is guaranteed that all border cells are impassable, so Igor can't go out from the museum. Each of the last k lines contains two integers x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.

Print k integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF598D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := [...]pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var n, m, q, x, y int
	Fscan(in, &n, &m, &q)
	g := make([][]byte, n)
	for i := range g {
		Fscan(in, &g[i])
	}
	ans := make([][]int, n)
	for i := range ans {
		ans[i] = make([]int, m)
	}
	for ; q > 0; q-- {
		Fscan(in, &x, &y)
		x--
		y--
		if ans[x][y] == 0 {
			todo, c := []pair{}, 0
			ans[x][y] = 1
			for q := []pair{{x, y}}; len(q) > 0; {
				p := q[0]
				q = q[1:]
				todo = append(todo, p)
				for _, d := range dir4 {
					if x, y := p.x+d.x, p.y+d.y; g[x][y] == '*' {
						c++
					} else if ans[x][y] == 0 {
						ans[x][y] = 1
						q = append(q, pair{x, y})
					}
				}
			}
			for _, p := range todo {
				ans[p.x][p.y] = c
			}
		}
		Fprintln(out, ans[x][y])
	}
}

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

package main

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

var museum [][]bool
var visited [][]bool
var resp [][]int
var n int
var m int

type Stack struct {
	Arr [][]int
}

func (s *Stack) Push(p []int) {
	s.Arr = append(s.Arr, p)
}

func (s *Stack) Pop() []int {
	curr := s.Arr[len(s.Arr)-1]
	s.Arr = s.Arr[:len(s.Arr)-1]
	return curr
}

func (s *Stack) Top() []int {
	return s.Arr[len(s.Arr) - 1]
}

func (s *Stack) Len() int {
	return len(s.Arr)
}

func (s *Stack) isEmpty() bool {
	return len(s.Arr) == 0
}

func currPicturesSeeing(x int, y int) int {
	resp := 0
	if x > 0 && !museum[x-1][y] {
		resp += 1
	}
	if y > 0 && !museum[x][y-1] {
		resp += 1
	}
	if x < n-1 && !museum[x+1][y] {
		resp += 1
	}
	if y < m-1 && !museum[x][y+1] {
		resp += 1
	}
	return resp
}

func picturesSeen(startX int, startY int) int {
	if visited[startX][startY] {
		return resp[startX][startY]
	}

	var currConn [][]int
	s := &Stack{}

	startPt := []int{startX, startY}
	s.Push(startPt)
	visited[startX][startY] = true
	picturesVis := 0
	for !s.isEmpty() {
		currPt := s.Pop()
		currConn = append(currConn, currPt)
		x := currPt[0]
		y := currPt[1]
		picturesVis += currPicturesSeeing(x, y)

		if x > 0 && museum[x-1][y] && !visited[x-1][y] {
			s.Push([]int{x-1, y})
			visited[x-1][y] = true
		}
		if y > 0 && museum[x][y-1] && !visited[x][y-1] {
			s.Push([]int{x, y-1})
			visited[x][y-1] = true
		}
		if x < n-1 && museum[x+1][y] && !visited[x+1][y] {
			s.Push([]int{x+1, y})
			visited[x+1][y] = true
		}
		if y < m-1 && museum[x][y+1] && !visited[x][y+1] {
			s.Push([]int{x, y+1})
			visited[x][y+1] = true
		}
	}

	for idx := range currConn {
		currPt := currConn[idx]
		resp[currPt[0]][currPt[1]] = picturesVis
	}
	return picturesVis
}

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

	if !scanner.Scan() || scanner.Err() != nil {
		panic(scanner.Err())
	}
	nmkStr := scanner.Text()
	nmkArr := strings.Split(nmkStr, " ")
	var err error
	n, err = strconv.Atoi(nmkArr[0])
	if err != nil {
		panic(err)
	}
	m, err = strconv.Atoi(nmkArr[1])
	if err != nil {
		panic(err)
	}
	k, err := strconv.Atoi(nmkArr[2])
	if err != nil {
		panic(err)
	}

	museum = make([][]bool, n)
	for idx := range museum {
		museum[idx] = make([]bool, m)

		if !scanner.Scan() || scanner.Err() != nil {
			panic(scanner.Err())
		}
		currRowStr := scanner.Text()
		for j := range museum[idx] {
			if string(currRowStr[j]) == "." {
				museum[idx][j] = true
			}
		}
	}

	visited = make([][]bool, n)
	for idx := range visited {
		visited[idx] = make([]bool, m)
	}

	resp = make([][]int, n)
	for idx := range resp {
		resp[idx] = make([]int, m)
	}

	for i := 0; i < k; i++ {
		if !scanner.Scan() || scanner.Err() != nil {
			panic(scanner.Err())
		}
		startStr := scanner.Text()
		startArr := strings.Split(startStr, " ")
		startX, err := strconv.Atoi(startArr[0])
		if err != nil {
			panic(err)
		}
		startX -= 1

		startY, err := strconv.Atoi(startArr[1])
		if err != nil {
			panic(err)
		}
		startY -= 1

		fmt.Println(picturesSeen(startX, startY))
	}
}

package main

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

var museum [][]bool
var visited [][]bool
var resp [][]int
var n int
var m int

type Stack struct {
	Arr [][]int
}

func (s *Stack) Push(p []int) {
	s.Arr = append(s.Arr, p)
}

func (s *Stack) Pop() []int {
	curr := s.Arr[len(s.Arr)-1]
	s.Arr = s.Arr[:len(s.Arr)-1]
	return curr
}

func (s *Stack) Top() []int {
	return s.Arr[len(s.Arr) - 1]
}

func (s *Stack) Len() int {
	return len(s.Arr)
}

func (s *Stack) isEmpty() bool {
	return len(s.Arr) == 0
}

func currPicturesSeeing(x int, y int) int {
	resp := 0
	if x > 0 && !museum[x-1][y] {
		resp += 1
	}
	if y > 0 && !museum[x][y-1] {
		resp += 1
	}
	if x < n-1 && !museum[x+1][y] {
		resp += 1
	}
	if y < m-1 && !museum[x][y+1] {
		resp += 1
	}
	return resp
}

func picturesSeen(startX int, startY int) int {
	if visited[startX][startY] {
		return resp[startX][startY]
	}

	var currConn [][]int
	s := &Stack{}

	startPt := []int{startX, startY}
	s.Push(startPt)

	picturesVis := 0
	for !s.isEmpty() {
		currPt := s.Pop()
		currConn = append(currConn, currPt)
		x := currPt[0]
		y := currPt[1]
		picturesVis += currPicturesSeeing(x, y)
		visited[x][y] = true
		if x > 0 && museum[x-1][y] && !visited[x-1][y] {
			s.Push([]int{x-1, y})
		}
		if y > 0 && museum[x][y-1] && !visited[x][y-1] {
			s.Push([]int{x, y-1})
		}
		if x < n-1 && museum[x+1][y] && !visited[x+1][y] {
			s.Push([]int{x+1, y})
		}
		if y < m-1 && museum[x][y+1] && !visited[x][y+1] {
			s.Push([]int{x, y+1})
		}
	}

	for idx := range currConn {
		currPt := currConn[idx]
		resp[currPt[0]][currPt[1]] = picturesVis
	}
	return picturesVis
}

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

	if !scanner.Scan() || scanner.Err() != nil {
		panic(scanner.Err())
	}
	nmkStr := scanner.Text()
	nmkArr := strings.Split(nmkStr, " ")
	var err error
	n, err = strconv.Atoi(nmkArr[0])
	if err != nil {
		panic(err)
	}
	m, err = strconv.Atoi(nmkArr[1])
	if err != nil {
		panic(err)
	}
	k, err := strconv.Atoi(nmkArr[2])
	if err != nil {
		panic(err)
	}

	museum = make([][]bool, n)
	for idx := range museum {
		museum[idx] = make([]bool, m)

		if !scanner.Scan() || scanner.Err() != nil {
			panic(scanner.Err())
		}
		currRowStr := scanner.Text()
		for j := range museum[idx] {
			if string(currRowStr[j]) == "." {
				museum[idx][j] = true
			}
		}
	}

	visited = make([][]bool, n)
	for idx := range visited {
		visited[idx] = make([]bool, m)
	}

	resp = make([][]int, n)
	for idx := range resp {
		resp[idx] = make([]int, m)
	}

	for i := 0; i < k; i++ {
		if !scanner.Scan() || scanner.Err() != nil {
			panic(scanner.Err())
		}
		startStr := scanner.Text()
		startArr := strings.Split(startStr, " ")
		startX, err := strconv.Atoi(startArr[0])
		if err != nil {
			panic(err)
		}
		startX -= 1

		startY, err := strconv.Atoi(startArr[1])
		if err != nil {
			panic(err)
		}
		startY -= 1

		fmt.Println(picturesSeen(startX, startY))
	}
}


Vanya plays a game of balloons on the field of size n × n, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. There are two types of crosses: normal and rotated. For example:**o****o**ooooo**o****o**oro***o*o*o***o***o*o*o***oFormally, the cross is given by three integers r, c and d, such that d ≤ r, c ≤ n - d + 1. The normal cross consists of balloons located in cells (x, y) (where x stay for the number of the row and y for the number of the column), such that |x - r|·|y - c| = 0 and |x - r| + |y - c| < d. Rotated cross consists of balloons located in cells (x, y), such that |x - r| = |y - c| and |x - r| < d.Vanya wants to know the maximum possible product of the values of balls forming one cross. As this value can be large, output it modulo 109 + 7.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows and columns in the table with balloons. The each of the following n lines contains n characters '0', '1', '2' or '3' — the description of the values in balloons.

Print the maximum possible product modulo 109 + 7. Note, that you are not asked to maximize the remainder modulo 109 + 7, but to find the maximum value and print it this modulo.

NoteIn the first sample, the maximum product is achieved for a rotated cross with a center in the cell (3, 3) and radius 1: 2·2·3·3·3 = 108.

package main

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

const N = 1002
const mod = 1000000000 + 7

var M [N][N]byte

type d2arr struct {
	cols int
	data []int
}

func newD2arr(rows, cols int) d2arr { return d2arr{cols, make([]int, cols*rows)} }
func (a d2arr) at(y, x int) int     { return a.data[a.cols*y+x] }
func (a d2arr) ref(y, x int) *int   { return &a.data[a.cols*y+x] }
func (a d2arr) set(y, x, v int)     { a.data[a.cols*y+x] = v }

type pair struct {
	d, t int // number of two's and three's
}
type d2arrP struct {
	cols int
	data []pair
}

func newD2arrP(rows, cols int) d2arrP { return d2arrP{cols, make([]pair, cols*rows)} }
func (a d2arrP) at(y, x int) pair     { return a.data[a.cols*y+x] }
func (a d2arrP) ref(y, x int) *pair   { return &a.data[a.cols*y+x] }
func (a d2arrP) set(y, x int, v pair) { a.data[a.cols*y+x] = v }
func minus(a, b pair) pair            { return pair{a.d - b.d, a.t - b.t} }
func plus(a, b pair) pair             { return pair{a.d + b.d, a.t + b.t} }

func main() {
	n := getInt()
	for i := 1; i <= n; i++ {
		s := getWord()
		copy(M[i][1:], s)
	}

	notbad := func(y, x int) bool {
		return M[y][x] >= '1'
	}
	all := func(_, _ int) bool { return true }

	foryx := func(dy, dx int, onlyif func(y, x int) bool, do func(y, x int)) {
		yb, ye, xb, xe := 1, n, 1, n
		if dy < 0 {
			yb, ye = n, 1
		}
		if dx < 0 {
			xb, xe = n, 1
		}
		ye += dy * 2 // it's safe to go to border
		xe += dx * 2
		for y := yb; y != ye; y += dy {
			for x := xb; x != xe; x += dx {
				if onlyif(y, x) {
					do(y, x)
				}
			}
		}
	}
	calcL := func(dy, dx int, py, px int) d2arr {
		a := newD2arr(n+2, n+2)
		uy, ux := dy*py, dx*px
		foryx(dy, dx, notbad, func(y, x int) {
			a.set(y, x, a.at(y-uy, x-ux)+1)
		})
		return a
	}
	calcS := func(dy, dx int, py, px int) d2arrP {
		a := newD2arrP(n+2, n+2)
		uy, ux := dy*py, dx*px
		foryx(dy, dx, all, func(y, x int) {
			c := a.ref(y, x)
			*c = a.at(y-uy, x-ux)
			switch M[y][x] {
			case '2':
				c.d++
			case '3':
				c.t++
			}
		})
		return a
	}

	maxcell := byte('0')
	foryx(1, 1, all, func(y, x int) {
		if c := M[y][x]; c > maxcell {
			maxcell = c
		}
	})
	if maxcell < '2' {
		fmt.Println(int(maxcell - '0'))
		return
	}

	U := calcL(1, 1, 1, 0)
	D := calcL(-1, 1, 1, 0)
	L := calcL(1, 1, 0, 1)
	R := calcL(1, -1, 0, 1)
	Q := calcL(1, 1, 1, 1)
	E := calcL(1, -1, 1, 1)
	C := calcL(-1, -1, 1, 1)
	Z := calcL(-1, 1, 1, 1)
	SU := calcS(1, 1, 1, 0)
	SL := calcS(1, 1, 0, 1)
	SZ := calcS(-1, 1, 1, 1)
	SC := calcS(-1, -1, 1, 1)

	poss := map[int]int{}
	cross := func(length []d2arr, sum []d2arrP, dy0, dx0, dy1, dx1 int) {
		foryx(1, 1, notbad, func(y, x int) {
			l := min(min(length[0].at(y, x), length[1].at(y, x)), min(length[2].at(y, x), length[3].at(y, x)))
			s := plus(
				minus(
					sum[0].at(y+dy0*(l-1), x+dx0*(l-1)),
					sum[0].at(y-dy0*l, x-dx0*l),
				), minus(
					sum[1].at(y+dy1*(l-1), x+dx1*(l-1)),
					sum[1].at(y-dy1*l, x-dx1*l),
				))
			switch M[y][x] {
			case '2':
				s.d--
			case '3':
				s.t--
			}
			//~ fmt.Println(dy0, dx0, dy1, dx1, y, x, l, M[y][x]-'0',
				//~ y+dy0*(l-1), x+dx0*(l-1), y-dy0*l, x-dx0*l, y+dy1*(l-1), x+dx1*(l-1), y-dy1*l, x-dx1*l,
				//~ sum[0].at(y+dy0*(l-1), x+dx0*(l-1)), sum[0].at(y-dy0*l, x-dx0*l),
				//~ sum[1].at(y+dy1*(l-1), x+dx1*(l-1)), sum[1].at(y-dy1*l, x-dx1*l),
				//~ s)

			poss[s.t] = max(poss[s.t], s.d)
		})
	}

	cross([]d2arr{U, D, L, R}, []d2arrP{SU, SL}, 1, 0, 0, 1)
	cross([]d2arr{Q, E, Z, C}, []d2arrP{SZ, SC}, -1, 1, -1, -1)

	p := make([]pair, 0, len(poss))
	for k, v := range poss {
		p = append(p, pair{v, k})
	}
	wsort(
		len(p), // len
		func(i, j int) bool { return p[i].t > p[j].t }, // less
		func(i, j int) { p[i], p[j] = p[j], p[i] },     // swap
	)

	mind, cut := 0, 0
	for i := 0; i < len(p); i++ {
		if mind <= p[i].d {
			p[cut] = p[i]
			cut++
			mind = p[i].d + 2
		}
	}
	p = p[:cut]
	//~ fmt.Println(p)

	best := p[0]
	tmp := big.NewInt(0)
	one := big.NewInt(1)

	for _, q := range p[1:] {
		z, v := best.t, best.d
		x, y := q.t, q.d
		if tmp.Lsh(one, uint(y-v)).Cmp(pow3(z-x)) == 1 {
			best = q
		}
	}

	bmod := big.NewInt(mod)
	fmt.Println(tmp.Mod(tmp.Mul(one.Lsh(one, uint(best.d)), tmp.Exp(big.NewInt(3), tmp.SetInt64(int64(best.t)), bmod)), bmod))
}

// 3^n
func pow3(n int) *big.Int {
	res := big.NewInt(1)
	x := big.NewInt(3)
	for n > 0 {
		if n&1 == 1 {
			res.Mul(res, x)
		}
		x.Mul(x, x)
		n >>= 1
	}
	return res
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}


This is an interactive problem.We hid from you a permutation $$$p$$$ of length $$$n$$$, consisting of the elements from $$$1$$$ to $$$n$$$. You want to guess it. To do that, you can give us 2 different indices $$$i$$$ and $$$j$$$, and we will reply with $$$p_{i} \bmod p_{j}$$$ (remainder of division $$$p_{i}$$$ by $$$p_{j}$$$).We have enough patience to answer at most $$$2 \cdot n$$$ queries, so you should fit in this constraint. Can you do it?As a reminder, a permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — length of the permutation.

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
}

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

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	n := nextInt()
	res := make([]int, n)

	curr := 0
	for i := 1; i < n; i++ {
		printf("? %d %d\n", curr+1, i+1)
		printf("? %d %d\n", i+1, curr+1)
		out.Flush()
		x, y := nextInt(), nextInt()
		if x < y {
			res[i] = y
		} else {
			res[curr] = x
			curr = i
		}
	}
	has := map[int]bool{}
	for _, v := range res {
		has[v] = true
	}
	for i := 1; i <= n; i++ {
		if !has[i] {
			res[curr] = i
		}
	}
	printf("! ")
	for _, v := range res {
		printf("%d ", v)
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		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:\n", i)
	solve()
	// }

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

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	var n int
	fmt.Scan(&n)

	mxi := 1
	a := make([]int, 10004)
	var kx, ky int
	for i:=2; i<=n; i++ {
		fmt.Println("? ", mxi, " ", i)
		fmt.Scan(&ky)
		fmt.Println("? ", i, " ", mxi)
		fmt.Scan(&kx)
		if kx > ky {
			a[i] = kx
		} else {
			a[mxi] = ky
			mxi = i
		}
	}
	a[mxi] = n
	fmt.Print("! ")
	for i := 1; i<=n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println("")
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)

	n := io.NextInt()
	ans := make([]int, n+1)
	i := 1
	for j := 2; j <= n; j++ {
		io.Println("?", i, j)
		ij := io.NextInt()
		io.Println("?", j, i)
		ji := io.NextInt()
		if ij < ji {
			ans[j] = ji
		} else {
			ans[i] = ij
			i = j
		}
	}
	ans[i] = n
	io.Print("! ")
	io.PrintlnInts(ans[1:])
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
	f.Flush()
}

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

func (f *FastIO) PrintlnInts(a []int) {
	f.PrintInts(a)
	f.Println()
}

package main

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

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

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

	n := in()

	a := make([]int, n)

	for n > 1 {
		b := make([]int, 0, n)

		for i := range a {
			if a[i] == 0 {
				b = append(b, i)
			}
		}

		for i := 0; i < len(b)-1; i += 2{
			j := b[i]
			k := b[i+1]

			fmt.Println("?", j+1, k+1)
			a1 := in()
			fmt.Println("?", k+1, j+1)
			a2 := in()

			if a1 > a2 {
				a[j] = a1
			} else {
				a[k] = a2
			}
			n--
		}
	}

	for i := range a {
		if a[i] == 0 {
			a[i] = len(a)
		}
	}

	fmt.Print("! ")

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

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	var n int
	fmt.Scan(&n)

	mxi := 1
	a := make([]int, 10004)
	var kx, ky int
	for i:=2; i<=n; i++ {
		fmt.Printf("? %d %d\n", mxi, i)
		fmt.Printf("? %d %d\n", i, mxi)
		fmt.Scan(&kx, &ky)
		if kx > ky {
			a[i] = kx
		} else if kx < ky {
			a[mxi] = ky
			mxi = i
		} else if kx == 1 {
			a[i] = 1
		}
	}
	a[mxi] = n
	fmt.Print("! ")
	for i := 1; i<=n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println("")
}

package main

import (
	"fmt"
	"os"
)

func main()  {
	fileInput, _ := os.Open("input.txt")
	os.Stdin = fileInput

	var n int
	fmt.Scan(&n)

	mxi := 1
	a := make([]int, 10004)
	var kx, ky int
	for i:=2; i<=n; i++ {
		fmt.Printf("? % %\n", mxi, i)
		fmt.Printf("? % %\n", i, mxi)
		fmt.Scan(kx, ky)
		if kx > ky {
			a[i] = kx
		} else if kx < ky {
			a[mxi] = ky
			mxi = i
		} else if kx == 1 {
			a[i] = 1
		}
	}
	a[mxi] = n
	fmt.Print("! ")
	for i := 1; i<=n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println("")
}

package main

import (
	"fmt"
	"os"
)

func main()  {
	fileInput, _ := os.Open("input.txt")
	os.Stdin = fileInput

	var n int
	fmt.Scan(&n)

	mxi := 1
	a := make([]int, 10004)
	var kx, ky int
	for i:=2; i<=n; i++ {
		fmt.Printf("? % %\n", mxi, i)
		fmt.Printf("? % %\n", i, mxi)
		fmt.Scan(&kx, &ky)
		if kx > ky {
			a[i] = kx
		} else if kx < ky {
			a[mxi] = ky
			mxi = i
		} else if kx == 1 {
			a[i] = 1
		}
	}
	a[mxi] = n
	fmt.Print("! ")
	for i := 1; i<=n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println("")
}

package main

import (
	"fmt"
)

func main()  {
	//fileInput, _ := os.Open("input.txt")
	//os.Stdin = fileInput

	var n int
	fmt.Scan(&n)

	mxi := 1
	a := make([]int, 10004)
	var kx, ky int
	for i:=2; i<=n; i++ {
		fmt.Printf("? % %\n", mxi, i)
		fmt.Printf("? % %\n", i, mxi)
		fmt.Scan(&kx, &ky)
		if kx > ky {
			a[i] = kx
		} else if kx < ky {
			a[mxi] = ky
			mxi = i
		} else if kx == 1 {
			a[i] = 1
		}
	}
	a[mxi] = n
	fmt.Print("! ")
	for i := 1; i<=n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println("")
}


Recently, the bear started studying data structures and faced the following problem.You are given a sequence of integers x1, x2, ..., xn of length n and m queries, each of them is characterized by two integers li, ri. Let's introduce f(p) to represent the number of such indexes k, that xk is divisible by p. The answer to the query li, ri is the sum: , where S(li, ri) is a set of prime numbers from segment [li, ri] (both borders are included in the segment).Help the bear cope with the problem.

The first line contains integer n (1 ≤ n ≤ 106). The second line contains n integers x1, x2, ..., xn (2 ≤ xi ≤ 107). The numbers are not necessarily distinct. The third line contains integer m (1 ≤ m ≤ 50000). Each of the following m lines contains a pair of space-separated integers, li and ri (2 ≤ li ≤ ri ≤ 2·109) — the numbers that characterize the current query.

Print m integers — the answers to the queries on the order the queries appear in the input.

NoteConsider the first sample. Overall, the first sample has 3 queries.  The first query l = 2, r = 11 comes. You need to count f(2) + f(3) + f(5) + f(7) + f(11) = 2 + 1 + 4 + 2 + 0 = 9.  The second query comes l = 3, r = 12. You need to count f(3) + f(5) + f(7) + f(11) = 1 + 4 + 2 + 0 = 7.  The third query comes l = 4, r = 4. As this interval has no prime numbers, then the sum equals 0.

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
)

func Primes(n int) (primes []int, fact []int) {
	fact = make([]int, n+1)
	for i := 2; i <= n; i++ {
		if fact[i] == 0 {
			for j := i; j <= n; j += i {
				fact[j] = i
			}
			primes = append(primes, i)
		}
	}
	return
}

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

func main() {
	const MAX = int(1e7)
	var (
		n, m     int
		cnt, sum [MAX + 1]int
		_, fact  = Primes(MAX)
	)

	fmt.Fscan(reader, &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		prev := -1
		for x != 1 {
			if fact[x] != prev {
				cnt[fact[x]]++
				prev = fact[x]
			}
			x /= fact[x]
		}
	}

	for i := range cnt {
		if i >= 2 {
			sum[i] = sum[i-1] + cnt[i]
		}
	}

	fmt.Fscan(reader, &m)
	for i := 0; i < m; i++ {
		var l, r int
		fmt.Fscan(reader, &l, &r)
		l = min(MAX+1, l)
		r = min(MAX, r)
		fmt.Println(sum[r] - sum[l-1])
	}
}