A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!You are given integers $$$n,k$$$. Construct a grid $$$A$$$ with size $$$n \times n$$$ consisting of integers $$$0$$$ and $$$1$$$. The very important condition should be satisfied: the sum of all elements in the grid is exactly $$$k$$$. In other words, the number of $$$1$$$ in the grid is equal to $$$k$$$.Let's define:  $$$A_{i,j}$$$ as the integer in the $$$i$$$-th row and the $$$j$$$-th column.  $$$R_i = A_{i,1}+A_{i,2}+...+A_{i,n}$$$ (for all $$$1 \le i \le n$$$).  $$$C_j = A_{1,j}+A_{2,j}+...+A_{n,j}$$$ (for all $$$1 \le j \le n$$$).  In other words, $$$R_i$$$ are row sums and $$$C_j$$$ are column sums of the grid $$$A$$$.  For the grid $$$A$$$ let's define the value $$$f(A) = (\max(R)-\min(R))^2 + (\max(C)-\min(C))^2$$$ (here for an integer sequence $$$X$$$ we define $$$\max(X)$$$ as the maximum value in $$$X$$$ and $$$\min(X)$$$ as the minimum value in $$$X$$$). Find any grid $$$A$$$, which satisfies the following condition. Among such grids find any, for which the value $$$f(A)$$$ is the minimum possible. Among such tables, you can find any.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case the only line contains two integers $$$n$$$, $$$k$$$ $$$(1 \le n \le 300, 0 \le k \le n^2)$$$. It is guaranteed that the sum of $$$n^2$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, firstly print the minimum possible value of $$$f(A)$$$ among all tables, for which the condition is satisfied. After that, print $$$n$$$ lines contain $$$n$$$ characters each. The $$$j$$$-th character in the $$$i$$$-th line should be equal to $$$A_{i,j}$$$. If there are multiple answers you can print any.

NoteIn the first test case, the sum of all elements in the grid is equal to $$$2$$$, so the condition is satisfied. $$$R_1 = 1, R_2 = 1$$$ and $$$C_1 = 1, C_2 = 1$$$. Then, $$$f(A) = (1-1)^2 + (1-1)^2 = 0$$$, which is the minimum possible value of $$$f(A)$$$.In the second test case, the sum of all elements in the grid is equal to $$$8$$$, so the condition is satisfied. $$$R_1 = 3, R_2 = 3, R_3 = 2$$$ and $$$C_1 = 3, C_2 = 2, C_3 = 3$$$. Then, $$$f(A) = (3-2)^2 + (3-2)^2 = 2$$$. It can be proven, that it is the minimum possible value of $$$f(A)$$$.

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

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

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

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

	for ; t > 0; t-- {
		scanf("\n%d %d", &n, &k)
		if k%n == 0 {
			printf("0\n")
		} else {
			printf("2\n")
		}

		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, n)
		}

		x, y := 0, 0
		for ; k > 0; k-- {
			arr[x][y] = 1
			x = (x + 1) % n
			y = (y + 1) % n
			if x == 0 {
				y = (y + 1) % n
			}
		}
		for _, v := range arr {
			for _, x := range v {
				printf("%d", x)
			}
			printf("\n")
		}
	}
}

package main

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

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

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		diff, G := solve(n, k)

		fmt.Println(diff)
		for i := 0; i < n; i++ {
			fmt.Println(string(G[i]))
		}
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(n, k int) (int, [][]byte) {
	G := make([][]byte, n)
	for i := 0; i < n; i++ {
		G[i] = make([]byte, n)
		for j := 0; j < n; j++ {
			G[i][j] = '0'
		}
	}

	var p, q int

	for i := 0; i < k; i++ {
		G[p][q] = '1'
		p++
		q = (q + 1) % n
		if p == n {
			p = 0
			q = (q + 1) % n
		}
	}

	var diff int

	if k%n != 0 {
		diff = 2
	}
	return diff, G
}

/*
URL:
https://codeforces.com/contest/1371/problem/D
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n, k int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k = ReadInt2()

		solve()
	}
}

func solve() {
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, n)
	}

	// j: 列の起点, kごとにループ
OUTER:
	for turn := 0; turn < n; turn++ {
		j := turn
		for i := 0; i < n; i++ {
			if k <= 0 {
				break OUTER
			}

			A[i][j%n] = 1
			j++

			k--
			if k <= 0 {
				break OUTER
			}
		}
	}

	// for i := 0; i < n; i++ {
	// 	PrintfDebug("%v\n", A[i])
	// }

	val := calc(A)
	ans := convert(A)

	fmt.Println(val)
	for i := 0; i < n; i++ {
		fmt.Println(string(ans[i]))
	}
}

func convert(B [][]int) [][]rune {
	res := make([][]rune, n)
	for i := 0; i < n; i++ {
		res[i] = make([]rune, n)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			res[i][j] = '0' + rune(B[i][j])
		}
	}

	return res
}

func calc(B [][]int) int {
	rsum := make([]int, n)
	csum := make([]int, n)

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			rsum[i] += B[i][j]
		}
	}

	for j := 0; j < n; j++ {
		for i := 0; i < n; i++ {
			csum[j] += B[i][j]
		}
	}

	maxR := Max(rsum...)
	minR := Min(rsum...)
	maxC := Max(csum...)
	minC := Min(csum...)

	res := (maxR-minR)*(maxR-minR) + (maxC-minC)*(maxC-minC)

	return res
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		c, k := k/n, k%n
		if k == 0 {
			Fprintln(out, 0)
		} else {
			Fprintln(out, 2)
		}
		s := make([]byte, n)
		for i := 0; i < n; i++ {
			for j := range s {
				s[j] = '0'
			}
			for d := 0; d < c; d++ {
				s[(i+d)%n] = '1'
			}
			if k > 0 {
				s[(i+c)%n] = '1'
				k--
			}
			Fprintln(out, string(s))
		}
	}
}

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

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		if k%n == 0 {
			Fprintln(out, 0)
		} else {
			Fprintln(out, 2)
		}
		c := k / n
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, n)
			for j := range ans[i] {
				ans[i][j] = '0'
			}
			for d := 0; d < c; d++ {
				ans[i][(i+d)%n] = '1'
			}
		}
		for i := 0; i < k%n; i++ {
			ans[i][(i+c)%n] = '1'
		}
		for _, row := range ans {
			Fprintln(out, string(row))
		}
	}
}

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

package main

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

var DEBUG = true

func main() {
	defer Flush()

	T := readi()
	for t := 0; t < T; t++ {
		n := readi()
		k := readi()
		a, v := solve(n, k)
		println(v)
		for i := range a {
			for _, v := range a[i] {
				printf("%d", v)
			}
			println()
		}

	}
}

func solve(n, k int) ([][]int, int) {
	c := 1
	if dif := n*n - k; dif < k {
		c = 0
		k = dif
	}
	d := 1 - c
	a := make([][]int, n)
	for i := range a {
		a[i] = make([]int, n)
		for j := range a[i] {
			a[i][j] = d
		}
	}

	i := 0
	j := 0
	f := 0
	for f < k {
		a[i][j] = c
		f++
		//dbg(i, j, "->")
		i, j = next(a, n, f, i, j, c)
		//dbg("->", i, j)
	}

	return a, calc(a)
}

func next(a [][]int, n, f, i, j, c int) (int, int) {
	//dbg(i, j, "=>")
	ni := (i + 1) % n
	nj := (j + 1) % n
	//dbg(ni, nj, "=>")
	if a[ni][nj] != c {
		return ni, nj
	}
	ni = (ni + 1) % n
	return ni, nj
	////dbg(ni, nj, "=> NG")
	//p := nj
	//q := ni
	////dbg(ni, nj, "=> ")
	//if a[p][q] != c {
	//	return p, q
	//}
	////dbg(ni, nj, "=> NG")
	//ni = ni + 1
	//nj = nj + 1
	////dbg(ni, nj, "=> ")
	//if a[ni][nj] != c {
	//	return ni, nj
	//}
	////dbg(ni, nj, "=> NG")

	//d := abs(ni - nj)
	////dbg("=>", 0, d+1)
	//return 0, d + 1
}

func calc(a [][]int) int {
	n := len(a)
	r := make([]int, n)
	c := make([]int, n)
	for i := range a {
		for j := range a[i] {
			c[j] += a[i][j]
			r[i] += a[i][j]
		}
	}

	var minc, maxc, minr, maxr int
	minc = n
	minr = n
	for _, v := range c {
		minc = min(minc, v)
		maxc = max(maxc, v)
	}
	for _, v := range r {
		minr = min(minr, v)
		maxr = max(maxr, v)
	}

	x := maxc - minc
	y := maxr - minr
	return x*x + y*y
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

import (
	"bufio"
	"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...)
}

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

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

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

	for ; t > 0; t-- {
		scanf("\n%d %d", &n, &k)
		if k%n == 0 {
			printf("0\n")
		} else {
			printf("2\n")
		}

		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, n)
		}

		per, ext := k/n, k%n

		for i := range arr {
			need := per
			if i < ext {
				need++
			}
			for j := range arr[i] {
				if j <= i && need < n-j {
					need -= arr[i][j]
				} else {
					if need > 0 {
						need--
						arr[i][j], arr[j][i] = 1, 1
					}
				}
				printf("%d", arr[i][j])
			}
			printf("\n")
		}
	}
}

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

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

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

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

	for ; t > 0; t-- {
		scanf("\n%d %d", &n, &k)
		if k%n == 0 {
			printf("0\n")
		} else {
			printf("2\n")
		}

		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, n)
		}

		per, ext := k/n, k%n

		for i := range arr {
			need := per
			if i < ext {
				need++
			}
			for j := range arr[i] {
				if j < i {
					need -= arr[i][j]
				} else {
					if need > 0 {
						need--
						arr[i][j], arr[j][i] = 1, 1
					}
				}
				printf("%d", arr[i][j])
			}
			printf("\n")
		}
	}
}

package main

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

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

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		diff, G := solve(n, k)

		fmt.Println(diff)
		for i := 0; i < n; i++ {
			fmt.Println(string(G[i]))
		}
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(n, k int) (int, [][]byte) {
	G := make([][]byte, n)
	for i := 0; i < n; i++ {
		G[i] = make([]byte, n)
		for j := 0; j < n; j++ {
			G[i][j] = '0'
		}
	}

	var p, q int

	for i := 0; i < k; i++ {
		G[p][q] = '1'
		p++
		q = (q + 1) % n
		if p == n {
			p = 0
			q = (q + 1) % n
		}
	}

	var diff int

	if k > 0 && n%k != 0 {
		diff = 2
	}
	return diff, G
}

package main

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

var DEBUG = true

func main() {
	defer Flush()

	T := readi()
	for t := 0; t < T; t++ {
		n := readi()
		k := readi()
		a, v := solve(n, k)
		println(v)
		for i := range a {
			for _, v := range a[i] {
				printf("%d", v)
			}
			println()
		}

	}
}

func solve(n, k int) ([][]int, int) {
	c := 1
	if dif := n*n - k; dif < k {
		c = 0
		k = dif
	}
	d := 1 - c
	a := make([][]int, n)
	for i := range a {
		a[i] = make([]int, n)
		for j := range a[i] {
			a[i][j] = d
		}
	}

	i := 0
	j := 0
	f := 0
	for f < k {
		a[i][j] = c
		f++
		//dbg(i, j, "->")
		i, j = next(a, n, f, i, j, c)
		//dbg("->", i, j)
	}

	return a, calc(a)
}

func next(a [][]int, n, f, i, j, c int) (int, int) {
	//dbg(i, j, "=>")
	ni := n - i - 1
	nj := n - j - 1
	//dbg(ni, nj, "=>")
	if a[ni][nj] != c {
		return ni, nj
	}
	//dbg(ni, nj, "=> NG")
	p := nj
	q := ni
	//dbg(ni, nj, "=> ")
	if a[p][q] != c {
		return p, q
	}
	//dbg(ni, nj, "=> NG")
	ni = ni + 1
	nj = nj + 1
	//dbg(ni, nj, "=> ")
	if a[ni][nj] != c {
		return ni, nj
	}
	//dbg(ni, nj, "=> NG")

	d := abs(ni - nj)
	//dbg("=>", 0, d+1)
	return 0, d + 1
}

func calc(a [][]int) int {
	n := len(a)
	r := make([]int, n)
	c := make([]int, n)
	for i := range a {
		for j := range a[i] {
			c[j] += a[i][j]
			r[i] += a[i][j]
		}
	}

	var minc, maxc, minr, maxr int
	minc = n
	minr = n
	for _, v := range c {
		minc = min(minc, v)
		maxc = max(maxc, v)
	}
	for _, v := range r {
		minr = min(minr, v)
		maxr = max(maxr, v)
	}

	return (maxc - minc) + (maxr - minr)
}

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

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

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

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

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

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

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

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

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

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

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) – the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <.

For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good.

NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <.

package main

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

func check(s string) int {
	l := len(s)
	i := 0
	j := l - 1
	for ; i < l; i++ {
		if s[i] != '<' {
			i--
			break
		}
	}
	for ; j >= 0; j-- {
		if s[j] != '>' {
			j++
			break
		}
	}

	return min(i+1, l-j)
}

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		s := ""
		n := 0
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		fmt.Println(check(s))
	}
}

package main

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

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

	var n, t int
	fmt.Fscanf(buf, "%d\n", &t)
	for tt := 0;tt < t;tt++ {
		fmt.Fscanf(buf, "%d\n", &n)
		str := make([]byte, n+1)
		fmt.Fscanf(buf, "%s\n", &str)
		var ans int = n + 1
		for i := 0; i < n; i++ {
			if str[i] == '>' {
				ans = i
				break
			}
		}
		for i := n - 1; i >= 0; i-- {
			if str[i] == '<' {
				if n-i-1 < ans {
					ans = n - i - 1
				}
				break
			}
		}
		fmt.Printf("%d\n", ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t, n := 0, 0
	fmt.Fscanf(in, "%d\n", &t)
	for ii := 0; ii < t; ii++ {
		fmt.Fscanf(in, "%d\n", &n)
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		if s[0] == '>' || s[n-1] == '<' || n == 1 {
			fmt.Fprintf(out, "0\n")
		} else {
			ans := n - 1
			for i := 0; i < n; i++ {
				if s[i] == '>' {
					if i < ans {
						ans = i
					}
					break
				}
			}
			for i := n - 1; i >= 0; i-- {
				if s[i] == '<' {
					if n-1-i < ans {
						ans = n - 1 - i
					}
					break
				}
			}
			fmt.Fprintf(out, "%d\n", ans)
		}
	}
	return
}

// Codeforces 1140 B Good String train
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

func readString() string {
	delim := byte('\n')
	s, err := in.ReadString(delim)
	s = strings.Trim(s, " \n\r")
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	return s
}

var n int
var s []string
var rmin []int

func readData() {
	in = bufio.NewReader(os.Stdin)
	n,_,_,_,_ = readFive()
	//fmt.Println("n = ", n)
	s = make([]string, n)
	rmin = make([]int, n)
	for i:=0; i<n; i++ {
		readString()
		s[i] = readString()
		//fmt.Println("Read string:", s[i])
	}
}

func solveOne(b []byte) int {
	ln := len(b)
	nl := 0
	for i:=0; i<ln; i++  {
		if b[i]=='<' {
			nl = i+1
		} else {
			break
		}
	}
	nr := 0
	for i:=ln-1; i>=0; i-- {
		if b[i]=='<' {
			nr = (ln-1) - i
			break
		}
	}
	rm := nl
	if nr<rm {rm = nr}
	return rm
}

func solve() {
	for i:=0; i<n; i++ {
		rmin[i] = solveOne(([]byte)(s[i]))
	}
}

func printRes() {
	for i:=0; i<n; i++ {
		fmt.Println(rmin[i])
	}
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var ln int
		fmt.Fscan(reader, &ln)
		var str string
		fmt.Fscan(reader, &str)

		for i := 0; i < ln; i++ {
			if str[i] == '>' {
				fmt.Println(i)
				break
			}

			if str[ln-i-1] == '<' {
				fmt.Println(i)
				break
			}
		}

		qr--
	}

}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var ln int
		fmt.Fscan(reader, &ln)
		var str string
		fmt.Fscan(reader, &str)

		if str[0] == '>' || str[ln-1] == '<' {
			fmt.Println(0)
			qr--
			continue
		}

		for i := 0; i < ln; i++ {
			if str[i] == '>' {
				fmt.Println(i)
				break
			}

			if str[ln-i-1] == '<' {
				fmt.Println(i)
				break
			}
		}

		qr--
	}

}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var ln int
		fmt.Fscan(reader, &ln)
		var str string
		fmt.Fscan(reader, &str)

		if str[0] == '>' || str[ln-1] == '<' {
			fmt.Println(0)
			qr--
			continue
		}

		var l, r int
		for i := 0; i < ln; i++ {
			if str[i] == '>' {
				l = i - 1
				break
			}
		}

		for i := ln - 1; i >= 0; i-- {
			if str[i] == '<' {
				r = i + 1
				break
			}
		}

		fmt.Println(min(l+1, ln-r))
		qr--
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t, n := 0, 0
	fmt.Fscanf(in, "%d\n", &t)
	for ii := 0; ii < t; ii++ {
		fmt.Fscanf(in, "%d\n", &n)
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		if s[0] == '>' || s[n-1] == '<' {
			fmt.Fprintf(out, "0\n")
		} else {
			fmt.Fprintf(out, "1\n")
		}
	}
	return
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var ln int
		fmt.Fscan(reader, &ln)
		var str string
		fmt.Fscan(reader, &str)

		if str[0] == '>' || str[ln-1] == '<' {
			fmt.Println(0)
			qr--
			continue
		}

		var l, r int
		for i := 0; i < ln; i++ {
			if str[i] == '>' {
				l = i - 1
				break
			}
		}

		for i := ln - 1; i >= 0; i-- {
			if str[i] == '<' {
				r = i + 1
				break
			}
		}

		fmt.Println(min(l+1, ln-r+1))
		qr--
	}

}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var ln int
		fmt.Fscan(reader, &ln)
		var str string
		fmt.Fscan(reader, &str)

		if str[0] == '>' || str[ln-1] == '<' {
			fmt.Println(0)
			qr--
			continue
		}

		var l, r int
		for i := 0; i < ln; i++ {
			if str[i] == '>' {
				l = i
				break
			}
		}

		for i := ln - 1; i >= 0; i-- {
			if str[i] == '<' {
				r = i
				break
			}
		}

		fmt.Println(min(l, ln-r+1))
		qr--
	}

}

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


Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.

NoteConsider the third test example. If you've made two tosses:  You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.  You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.  You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.  You can get 2 in the first toss, and 2 in the second. Maximum equals to 2. The probability of each outcome is 0.25, that is expectation equals to: You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

package main

import "bufio"
import "fmt"
import "math"
import "os"
import "strconv"

type MyScanner struct {
	in *bufio.Scanner
}

var in = MyScanner{bufio.NewScanner(os.Stdin)}

func ScanInts(data []byte, atEOF bool) (advance int, token []byte, err error) {
	advance, token, err = bufio.ScanWords(data, atEOF)
	if err == nil && token != nil {
		_, err = strconv.Atoi(string(token))
	}
	return
}

func (m *MyScanner) innerNext(f bufio.SplitFunc) bool {
	m.in.Split(f)
	return m.in.Scan()
}

func (m *MyScanner) NextInt() (int, error) {
	if !m.innerNext(ScanInts) {
		return 0, m.in.Err()
	}
	return strconv.Atoi(m.in.Text())
}

func main() {
	m, _ := in.NextInt()
	n, _ := in.NextInt()
	a := make([]float64, m+1)
	r := 0.0
	for i := 1; i <= m; i++ {
		a[i] = math.Pow(float64(i)/float64(m), float64(n))
	}
	for i := m; i >= 1; i-- {
		r += float64(i) * (a[i] - a[i-1])
	}
	fmt.Println(r)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/453/A

package main

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

func Solve(m, n float64) float64 {
	sum := float64(0)
	for i := float64(1); i <= m; i++ {
		sum += i * (math.Pow(i/m, n) - math.Pow((i-1)/m, n))
	}
	return sum
}

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

	var m, n float64
	fmt.Fscanf(reader, "%f %f\n", &m, &n)

	fmt.Fprintf(writer, "%f\n", Solve(m, n))
}