Welcome! Everything is fine.You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.You have a list of $$$k$$$ pairs of people who have arrived in a new inhabited neighborhood. You need to assign each of the $$$2k$$$ people into one of the $$$2k$$$ houses. Each person will be the resident of exactly one house, and each house will have exactly one resident.Of course, in the neighborhood, it is possible to visit friends. There are $$$2k - 1$$$ roads, each of which connects two houses. It takes some time to traverse a road. We will specify the amount of time it takes in the input. The neighborhood is designed in such a way that from anyone's house, there is exactly one sequence of distinct roads you can take to any other house. In other words, the graph with the houses as vertices and the roads as edges is a tree.The truth is, these $$$k$$$ pairs of people are actually soulmates. We index them from $$$1$$$ to $$$k$$$. We denote by $$$f(i)$$$ the amount of time it takes for the $$$i$$$-th pair of soulmates to go to each other's houses.As we have said before, you will need to assign each of the $$$2k$$$ people into one of the $$$2k$$$ houses. You have two missions, one from the entities in The Good Place and one from the entities of The Bad Place. Here they are:  The first mission, from The Good Place, is to assign the people into the houses such that the sum of $$$f(i)$$$ over all pairs $$$i$$$ is minimized. Let's define this minimized sum as $$$G$$$. This makes sure that soulmates can easily and efficiently visit each other;  The second mission, from The Bad Place, is to assign the people into the houses such that the sum of $$$f(i)$$$ over all pairs $$$i$$$ is maximized. Let's define this maximized sum as $$$B$$$. This makes sure that soulmates will have a difficult time to visit each other. What are the values of $$$G$$$ and $$$B$$$?

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) denoting the number of test cases. The next lines contain descriptions of the test cases. The first line of each test case contains a single integer $$$k$$$ denoting the number of pairs of people ($$$1 \le k \le 10^5$$$). The next $$$2k - 1$$$ lines describe the roads; the $$$i$$$-th of them contains three space-separated integers $$$a_i, b_i, t_i$$$ which means that the $$$i$$$-th road connects the $$$a_i$$$-th and $$$b_i$$$-th houses with a road that takes $$$t_i$$$ units of time to traverse ($$$1 \le a_i, b_i \le 2k$$$, $$$a_i \neq b_i$$$, $$$1 \le t_i \le 10^6$$$). It is guaranteed that the given roads define a tree structure. It is guaranteed that the sum of the $$$k$$$ in a single file is at most $$$3 \cdot 10^5$$$.

For each test case, output a single line containing two space-separated integers $$$G$$$ and $$$B$$$.

NoteFor the sample test case, we have a minimum sum equal to $$$G = 15$$$. One way this can be achieved is with the following assignment:  The first pair of people get assigned to houses $$$5$$$ and $$$6$$$, giving us $$$f(1) = 5$$$;  The second pair of people get assigned to houses $$$1$$$ and $$$4$$$, giving us $$$f(2) = 6$$$;  The third pair of people get assigned to houses $$$3$$$ and $$$2$$$, giving us $$$f(3) = 4$$$. Note that the sum of the $$$f(i)$$$ is $$$5 + 6 + 4 = 15$$$. We also have a maximum sum equal to $$$B = 33$$$. One way this can be achieved is with the following assignment:  The first pair of people get assigned to houses $$$1$$$ and $$$4$$$, giving us $$$f(1) = 6$$$;  The second pair of people get assigned to houses $$$6$$$ and $$$2$$$, giving us $$$f(2) = 14$$$;  The third pair of people get assigned to houses $$$3$$$ and $$$5$$$, giving us $$$f(3) = 13$$$. Note that the sum of the $$$f(i)$$$ is $$$6 + 14 + 13 = 33$$$.

package main

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

type edge struct {
	id int
	n1 *node
	n2 *node
	w int
	left int
}

type node struct {
	id int
	edges []*edge
}
var edges []*edge
var nodes []*node
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 1
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		edges = make([]*edge, 2 * n)
		nodes = make([]*node, 2 *n+1)
		for i := 1; i <= 2 * n; i++ {
			nodes[i] = &node{i, []*edge{}}
		}
		for i := 1; i <= 2 * n -1; i++ {
			a, b, c := 0, 0, 0
			fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
			n1 := nodes[a]
			n2 := nodes[b]
			edges[i] = &edge{i,n1, n2, c, 0}
			n1.edges = append(n1.edges, edges[i])
			n2.edges = append(n2.edges, edges[i])
		}
		solveNode(nodes[1], nil)
		//fmt.Println("debug")
		//for i := 1; i < len(edges); i++ {
		//	fmt.Println(edges[i])
		//}
		ans1 := int64(0)
		ans2 := int64(0)
		for i := 1; i <= 2 * n -1; i++ {
			ans1 += int64(edges[i].left % 2 * edges[i].w)
			ans2 += int64(min(edges[i].left, 2 * n - edges[i].left)) * int64(edges[i].w)
		}
		fmt.Fprintf(out, "%d %d\n", ans1, ans2)
	}
	return
}

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

func solve(e *edge, from *node) int {
	n1 := e.n1
	n2 := e.n2
	cur := 0
	if n1 != from {
		cur += solveNode(n1, e)
		e.left = cur
	}
	if n2 != from {
		cur += solveNode(n2, e)
		e.left = cur
	}
	return e.left
}

func solveNode(n *node, from *edge) int {
	if len(n.edges) == 1 && n.edges[0] == from{
		return 1
	}
	cur := 1
	for _, e := range n.edges {
		if e != from {
			cur += solve(e, n)
		}
	}
	return cur
}

package main

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

type edge struct {
	to int
	w int
}

type node struct {
	id int
	gw int
	bw int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 1
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		edges := make([][]edge, 2 * n+1)
		degree := make([]int, 2 * n + 1)
		nodes := make([]node, 2 *n+1)
		for i := 1; i <= 2 * n; i++ {
			nodes[i] = node{i, 1, 1}
		}
		for i := 0; i < 2 * n -1; i++ {
			a, b, c := 0, 0, 0
			fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
			//fmt.Println(a, b, c)
			edges[a] = append(edges[a], edge{b,c})
			edges[b] = append(edges[b], edge{a, c})
			degree[a]++
			degree[b]++
		}
		queue := make([]int, 0)
		visited := make([]bool, 2 *n+1)
		remaining := 2 * n
		for i := 1; i <= 2*n; i++ {
			if degree[i] == 1 {
				queue = append(queue, i)
				visited[i] = true
			}
		}
		ans1, ans2 := 0, 0
		for len(queue) > 0 {
			//fmt.Println(queue)
			if remaining == 2 {
				cur := queue[0]
				for _, e := range edges[nodes[cur].id] {
					if e.to == queue[1] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * min(nodes[cur].bw, nodes[e.to].bw)
					}
					break
				}
				break
			}
			newQueue := []int{}
			for len(queue) != 0 {
				cur := queue[0]
				queue = queue[1:]
				for _, e := range edges[nodes[cur].id] {
					if !visited[e.to] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * min(nodes[cur].bw, 2 * n - nodes[cur].bw)
						nodes[e.to].bw += nodes[cur].bw
						//nodes[e.to].bw = min(nodes[e.to].bw, 2 * n - nodes[e.to].bw)
						nodes[e.to].gw += nodes[cur].gw
						nodes[e.to].gw %= 2
						degree[e.to]--
						if degree[e.to] == 1 {
							newQueue = append(newQueue, e.to)
						}
					}
				}
				visited[cur] = true
			}
			queue = newQueue
			//fmt.Println(nodes)
		}
		fmt.Fprintf(out, "%d %d\n", ans1, ans2)
	}
	return
}

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

package main

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

type edge struct {
	to int
	w int
}

type node struct {
	id int
	gw int
	bw int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 1
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		edges := make([][]edge, 2 * n+1)
		degree := make([]int, 2 * n + 1)
		nodes := make([]node, 2 *n+1)
		for i := 1; i <= 2 * n; i++ {
			nodes[i] = node{i, 1, 1}
		}
		for i := 0; i < 2 * n -1; i++ {
			a, b, c := 0, 0, 0
			fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
			//fmt.Println(a, b, c)
			edges[a] = append(edges[a], edge{b,c})
			edges[b] = append(edges[b], edge{a, c})
			degree[a]++
			degree[b]++
		}
		queue := make([]int, 0)
		visited := make([]bool, 2 *n+1)
		remaining := 2 * n
		for i := 1; i <= 2*n; i++ {
			if degree[i] == 1 {
				queue = append(queue, i)
				visited[i] = true
			}
		}
		ans1, ans2 := 0, 0
		for len(queue) > 0 {
			//fmt.Println(queue)
			if remaining == 2 {
				cur := queue[0]
				for _, e := range edges[nodes[cur].id] {
					if e.to == queue[1] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * nodes[cur].bw
					}
					break
				}
				break
			}
			newQueue := []int{}
			for len(queue) != 0 {
				cur := queue[0]
				queue = queue[1:]
				for _, e := range edges[nodes[cur].id] {
					if !visited[e.to] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * nodes[cur].bw
						nodes[e.to].bw += nodes[cur].bw
						nodes[e.to].bw = min(nodes[e.to].bw, 2 * n - nodes[e.to].bw)
						nodes[e.to].gw += nodes[cur].gw
						nodes[e.to].gw %= 2
						degree[e.to]--
						if degree[e.to] == 1 {
							newQueue = append(newQueue, e.to)
						}
					}
				}
				visited[cur] = true
			}
			queue = newQueue
			//fmt.Println(nodes)
		}
		fmt.Fprintf(out, "%d %d\n", ans1, ans2)
	}
	return
}

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

package main

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

type edge struct {
	to int
	w int
}

type node struct {
	id int
	gw int
	bw int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 1
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		edges := make([][]edge, 2 * n+1)
		degree := make([]int, 2 * n + 1)
		nodes := make([]node, 2 *n+1)
		for i := 1; i <= 2 * n; i++ {
			nodes[i] = node{i, 1, 1}
		}
		for i := 0; i < 2 * n -1; i++ {
			a, b, c := 0, 0, 0
			fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
			//fmt.Println(a, b, c)
			edges[a] = append(edges[a], edge{b,c})
			edges[b] = append(edges[b], edge{a, c})
			degree[a]++
			degree[b]++
		}
		queue := make([]int, 0)
		visited := make([]bool, 2 *n+1)
		remaining := 2 * n
		for i := 1; i <= 2*n; i++ {
			if degree[i] == 1 {
				queue = append(queue, i)
				visited[i] = true
			}
		}
		ans1, ans2 := 0, 0
		for len(queue) > 0 {
			//fmt.Println(queue)
			if remaining == 2 {
				cur := queue[0]
				for _, e := range edges[nodes[cur].id] {
					if e.to == queue[1] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * min(nodes[cur].bw, nodes[e.to].bw)
					}
					break
				}
				break
			}
			newQueue := []int{}
			for len(queue) != 0 {
				cur := queue[0]
				queue = queue[1:]
				for _, e := range edges[nodes[cur].id] {
					if !visited[e.to] {
						ans1 += e.w * nodes[cur].gw
						ans2 += e.w * nodes[cur].bw
						nodes[e.to].bw += nodes[cur].bw
						nodes[e.to].bw = min(nodes[e.to].bw, 2 * n - nodes[e.to].bw)
						nodes[e.to].gw += nodes[cur].gw
						nodes[e.to].gw %= 2
						degree[e.to]--
						if degree[e.to] == 1 {
							newQueue = append(newQueue, e.to)
						}
					}
				}
				visited[cur] = true
			}
			queue = newQueue
			//fmt.Println(nodes)
		}
		fmt.Fprintf(out, "%d %d\n", ans1, ans2)
	}
	return
}

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


To celebrate your birthday you have prepared a festive table! Now you want to seat as many guests as possible.The table can be represented as a rectangle with height $$$h$$$ and width $$$w$$$, divided into $$$h \times w$$$ cells. Let $$$(i, j)$$$ denote the cell in the $$$i$$$-th row and the $$$j$$$-th column of the rectangle ($$$1 \le i \le h$$$; $$$1 \le j \le w$$$).Into each cell of the table you can either put a plate or keep it empty.As each guest has to be seated next to their plate, you can only put plates on the edge of the table — into the first or the last row of the rectangle, or into the first or the last column. Formally, for each cell $$$(i, j)$$$ you put a plate into, at least one of the following conditions must be satisfied: $$$i = 1$$$, $$$i = h$$$, $$$j = 1$$$, $$$j = w$$$.To make the guests comfortable, no two plates must be put into cells that have a common side or corner. In other words, if cell $$$(i, j)$$$ contains a plate, you can't put plates into cells $$$(i - 1, j)$$$, $$$(i, j - 1)$$$, $$$(i + 1, j)$$$, $$$(i, j + 1)$$$, $$$(i - 1, j - 1)$$$, $$$(i - 1, j + 1)$$$, $$$(i + 1, j - 1)$$$, $$$(i + 1, j + 1)$$$.Put as many plates on the table as possible without violating the rules above.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each of the following $$$t$$$ lines describes one test case and contains two integers $$$h$$$ and $$$w$$$ ($$$3 \le h, w \le 20$$$) — the height and the width of the table.

For each test case, print $$$h$$$ lines containing $$$w$$$ characters each. Character $$$j$$$ in line $$$i$$$ must be equal to $$$1$$$ if you are putting a plate into cell $$$(i, j)$$$, and $$$0$$$ otherwise. If there are multiple answers, print any. All plates must be put on the edge of the table. No two plates can be put into cells that have a common side or corner. The number of plates put on the table under these conditions must be as large as possible. You are allowed to print additional empty lines.

NoteFor the first test case, example output contains the only way to put $$$6$$$ plates on the table.For the second test case, there are many ways to put $$$4$$$ plates on the table, example output contains one of them.Putting more than $$$6$$$ plates in the first test case or more than $$$4$$$ plates in the second test case is impossible.

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var h,w int
		h, input = GetInt(input)
		w, _ = GetInt(input)

		// Solve
		for i:=1; i<=h; i++ {
			if i & 0x1 == 1 {
				if i == 1 || i == h {
					for j:=1; j<w-1; j+=2 {
						fmt.Printf("10")
					}
					if w & 0x1 == 0 {
						fmt.Printf("01")

					} else {
						fmt.Printf("1")
					}

				} else {
					fmt.Printf("1")
					for j:=2; j<w; j++ {
						fmt.Printf("0")
					}
					fmt.Printf("1")
				}

			} else {
				if i == h && w > 4 {
					fmt.Printf("00")
					for j:=1; j<=w-4; j++ {
						if j & 0x1 == 1 {
							fmt.Printf("1")

						} else {
							fmt.Printf("0")
						}
					}
					fmt.Printf("00")

				} else {
					for j:=0; j<w; j++ {
						fmt.Printf("0")
					}
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

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

func (in *CF1530B) GetLine() string {
  line, err := in.sc.ReadString('\n')
  if err != nil {
    fmt.Println("error line:", line, " err: ", err)
  }
  in.split = []string{}
  in.index = 0
  return line
}
func (in *CF1530B) load() {
  if len(in.split) <= in.index {
    in.split = strings.Split(in.GetLine(), in.separator)
    in.index = 0
  }
}

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

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

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

/**
Run solve the problem CF1530B
Date: 9/5/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1530/B
Problem: CF1530B
**/
func (in *CF1530B) Run() {
  for t := in.NextInt(); t > 0; t-- {
    h, w := in.NextInt(), in.NextInt()

    m := make([][]int, h)
    for i := 0; i < h; i++ {
      m[i] = make([]int, w)
    }
    var str strings.Builder
    for i := 0; i < h; i++ {
      for j := 0; j < w; j++ {
        if valid(&m, i, j, h, w) {
          m[i][j] = 1
          str.WriteString("1")
        } else {
          str.WriteString("0")
        }

      }
      str.WriteString("\n")
    }
    fmt.Print(str.String())
  }
}

func valid(m *[][]int, a, b, h, w int) bool {
  dx := []int{1, -1, 0, 0, 1, -1, 1, -1}
  dy := []int{0, 0, 1, -1, 1, -1, -1, 1}

  if a >= 1 && b >= 1 && a < h-1 && b < w-1 {
    return false
  }
  count := 0
  for i := 0; i < len(dx); i++ {
    x, y := a+dx[i], b+dy[i]
    if x >= 0 && x < h && y >= 0 && y < w && (*m)[x][y] == 1 {
      count++
    }
  }
  return count == 0
}

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

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

package main

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

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

func (in *CF1530B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1530B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1530B
Date: 9/5/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1530/B
Problem: CF1530B
**/
func (in *CF1530B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		h, w := in.NextInt(), in.NextInt()

		m := make([][]int, h)
		for i := 0; i < h; i++ {
			m[i] = make([]int, w)
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if valid(&m, i, j, h, w) {
					m[i][j] = 1
				}
			}
		}

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

	}
}

func valid(m *[][]int, a, b, h, w int) bool {
	dx := []int{1, -1, 0, 0, 1, -1, 1, -1}
	dy := []int{0, 0, 1, -1, 1, -1, -1, 1}

	if a >= 1 && b >= 1 && a < h-1 && b < w-1 {
		return false
	}
	count := 0
	for i := 0; i < len(dx); i++ {
		x, y := a+dx[i], b+dy[i]
		if x >= 0 && x < h && y >= 0 && y < w && (*m)[x][y] == 1 {
			count++
		}
	}
	return count == 0
}

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

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

package main

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

func solve() {
    f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, r, c := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &r, &c)
		o := make([][]int, r)
		for j := 0; j < r; j++ {
			o[j] = make([]int, c)
			if j&1 == 1 {
				continue
			}
			for k := 0; k < c; k++ {
				if k&1 == 0 && (j == 0 || j == r-1) {
					o[j][k] = 1
				} else if 0 < j && j < r-1 && (k == 0 || k == c-1) {
					o[j][k] = 1
				}
			}
		}
		if r > 2 && r&1 == 0 {
			o[r-1], o[r-2] = o[r-2], o[r-1]
			copy(o[r-1], o[0])
		}
		for j := 0; j < r; j++ {
			for k := 0; k < c; k++ {
				fmt.Fprint(w, o[j][k])
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, " ")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var height, width int
	fmt.Fscan(in, &height)
	fmt.Fscan(in, &width)
	var matrix = make([][]int, height)
	for i := 0; i < height; i++ {
		matrix[i] = make([]int, width)
	}
	top := 0
	bottom := len(matrix) - 1
	right := 0
	left := len(matrix[0]) - 1
	for i := 0; i < len(matrix[0]); i++ {
		if canput(top, i, matrix) {
			matrix[0][i] = 1
		}
	}
	for i := 0; i < len(matrix[0]); i++ {
		if canput(bottom, i, matrix) {
			matrix[bottom][i] = 1
		}
	}

	for i := 0; i < len(matrix); i++ {
		if canput(i, right, matrix) {
			matrix[i][right] = 1
		}
	}

	for i := 0; i < len(matrix); i++ {
		if canput(i, left, matrix) {
			matrix[i][left] = 1
		}
	}
	for i := 0; i < len(matrix); i++ {
		for j := 0; j < len(matrix[0]); j++ {
			fmt.Print(matrix[i][j])
		}
		fmt.Println()
	}
	fmt.Println()
}

func canput(currentX int, currentY int, matrix [][]int) bool {
	if currentX-1 >= 0 {
		tempX := currentX - 1
		if matrix[tempX][currentY] == 1 {
			return false
		}
		if currentY-1 >= 0 && matrix[tempX][currentY-1] == 1 {
			return false
		}
		if currentY+1 < len(matrix[0]) && matrix[tempX][currentY+1] == 1 {
			return false
		}

	}
	if currentX+1 < len(matrix) {
		tempX := currentX + 1
		if matrix[tempX][currentY] == 1 {
			return false
		}
		if currentY-1 >= 0 && matrix[tempX][currentY-1] == 1 {
			return false
		}
		if currentY+1 < len(matrix[0]) && matrix[tempX][currentY+1] == 1 {
			return false
		}
	}
	if currentY-1 >= 0 {
		if matrix[currentX][currentY-1] == 1 {
			return false
		}
	}
	if currentY+1 < len(matrix[0]) && matrix[currentX][currentY+1] == 1 {
		return false
	}
	return true
}

package main

import "fmt"

func main() {
   var t int
   fmt.Scanln(&t)
   for T := 0; T < t; T++ {
       var h, w int
       fmt.Scanln(&h, &w)
       for i := 0; i < h; i++ {
           if (i == 0 || i == h-1) {
               if (w % 2 == 0) {
                   for j := 0; j < w; j++ {
                       if ((j % 2 == 0 && j != w-2) || j == w-1) {
                           fmt.Print("1")
                       } else {
                           fmt.Print("0")
                       }
                   }
               } else {
                   for j := 0; j < w; j++ {
                       if (j % 2 == 0) {
                           fmt.Print("1")
                       } else {
                           fmt.Print("0")
                       }
                   }
               }
               fmt.Println()
           } else {
               if (h % 2 == 1 && i % 2 == 0) {
                   fmt.Print("1")
                   for j := 1; j < w-1; j++ {
                       fmt.Print("0")
                   }
                   fmt.Println("1")
               } else if (h % 2 == 0 && i % 2 == 0 && i != h-2) {
                   fmt.Print("1")
                   for j := 1; j < w-1; j++ {
                       fmt.Print("0")
                   }
                   fmt.Println("1")
               } else {
                   for j := 0; j < w; j++ {
                       fmt.Print("0")
                   }
                   fmt.Println()
               }
           }
       }
       fmt.Println()
   }
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, m int
)

func isSorted(a []int) bool {
	for i := range a {
		if a[i] != i+1 {
			return false
		}
	}
	return true
}

func solve(n, m int) string {
	x := make([]string, n)
	for i := range x {
		if i == 0 {
			x[i] = strings.Repeat("10", (m+1)/2)[:m]
			continue
		}
		if i == n-1 {
			y := strings.Repeat("10", (m+1)/2)[:m]
			if i%2 == 1 {
				y = "00" + y[2:]
				y = y[:len(y)-2] + "00"
			}
			x[i] = y
			continue
		}
		if i%2 == 1 {
			x[i] = strings.Repeat("0", m)
			continue
		}
		if i%2 == 0 {
			x[i] = "1" + strings.Repeat("0", m-2) + "1"
			continue
		}
	}

	return strings.Join(x, "\n")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)
		fmt.Println(solve(n, m))
	}
}

package main

import "fmt"

func main() {
	var t int16
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		return
	}

	for i := 0; int16(i) < t; i++ {
		var h uint8
		var w uint8

		_, err := fmt.Scanf("%d %d\n", &h, &w)
		if err != nil {
			return
		}

		result := make([][]int, h + 2)
		for key := range result {
			result[key] = make([]int, w + 2)
		}

		var i uint8
		for i = 1; i <= h; i++ {
			var j uint8
			for j = 1; j <= w; j++ {
				if i == 1 || i == h || j == 1 || j == w {
					if result[i - 1][j] == 0 && result[i][j - 1] == 0 && result[i + 1][j] == 0 && result[i][j + 1] == 0 && result[i - 1][j - 1] == 0 && result[i - 1][j + 1] == 0 && result[i + 1][j - 1] == 0 && result[i + 1][j + 1] == 0 {
						result[i][j] = 1
					}
				}
			}
		}

		for i = 1; i <= h; i++ {
			var j uint8
			for j = 1; j <= w; j++ {
				fmt.Print(result[i][j])
			}
			fmt.Println()
		}
		fmt.Println()
	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var h, w int
		fmt.Scan(&h, &w)
		// first line
		for j := 0; j < w; j++ {
			if j%2 == 0 {
				fmt.Print(1)
			} else {
				fmt.Print(0)
			}
		}
		fmt.Println()

		if h%2 == 0 {
			for j := 0; j < w; j++ {
				fmt.Print(0)
			}
			fmt.Println()
			h--
		}
		for i := 1; i < h-1; i++ {
			x := 0
			if i%2 == 0 {
				x = 1
			}
			fmt.Print(x)
			for j := 1; j < w-1; j++ {
				fmt.Print(0)
			}
			fmt.Println(x)
		}

		// last line
		for j := 0; j < w; j++ {
			if j%2 == 0 {
				fmt.Print(1)
			} else {
				fmt.Print(0)
			}
		}
		fmt.Println()
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var h, w int
		_, _ = fmt.Fscan(in, &h, &w)

		mat := make([][]int, h)
		for i := 0; i < h; i++ {
			mat[i] = make([]int, w)
		}

		for i := 0; i < w; i += 2 {
			mat[0][i] = 1
			mat[h-1][i] = 1
		}

		for i := 2; i+2 < h; i += 2 {
			mat[i][0] = 1
			mat[i][w-1] = 1
		}

		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				_, _ = fmt.Fprintf(out, "%d", mat[i][j])
			}
			_, _ = fmt.Fprintln(out)
		}

		_, _ = fmt.Fprintln(out)
	}

	_ = out.Flush()
}

func abs(n int) int {
	if n < 0 {
		n = -n
	}

	return n
}

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
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		h := _int()
		w := _int()
		ret := make([][]byte, h)
		for i := range ret {
			ret[i] = make([]byte, w)
			for j := range ret[i] {
				ret[i][j] = '0'
			}
		}
		var fill func(int, int)
		fill = func(r, c int) {
			if r >= 0 && r < h && c >= 0 && c < w {
				for _, d := range [][2]int{
					{0, 1},
					{0, -1},
					{1, 1},
					{1, 0},
					{1, -1},
					{-1, 0},
					{-1, -1},
					{-1, 1},
				} {
					rn := r + d[0]
					cn := c + d[1]
					if rn >= 0 && rn < h && cn >= 0 && cn < w && ret[rn][cn] == '1' {
						return
					}
				}
				ret[r][c] = '1'
			}
		}
		fill(0, 0)
		for i := 1; i < w; i++ { // first row
			fill(0, i)
		}
		for i := 1; i < h; i++ { // first col
			fill(i, 0)
		}
		for i := 1; i < w; i++ { // last row
			fill(h-1, i)
		}
		for i := 1; i < h; i++ { // last col
			fill(i, w-1)
		}
		for _, row := range ret {
			printf("%s\n", string(row))
		}
	}
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var h,w int
		h, input = GetInt(input)
		w, _ = GetInt(input)

		// Solve
		for i:=1; i<=h; i++ {
			if i & 0x1 == 1 {
				if i == 1 || i == h {
					for j:=1; j<w-1; j+=2 {
						fmt.Printf("10")
					}
					if w & 0x1 == 0 {
						fmt.Printf("01")

					} else {
						fmt.Printf("1")
					}

				} else {
					fmt.Printf("1")
					for j:=2; j<w; j++ {
						fmt.Printf("0")
					}
					fmt.Printf("1")
				}

			} else {
				if i == h && i & 0x1 == 0 && h > 4 {
					fmt.Printf("00")
					for j:=1; j<=w-4; j++ {
						if j & 0x1 == 1 {
							fmt.Printf("1")

						} else {
							fmt.Printf("0")
						}
					}
					fmt.Printf("00")

				} else {
					for j:=0; j<w; j++ {
						fmt.Printf("0")
					}
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var h,w int
		h, input = GetInt(input)
		w, _ = GetInt(input)

		// Solve
		for i:=1; i<=h; i++ {
			if i & 0x1 == 1 {
				if i == 1 || i == h {
					for j:=1; j<w-1; j+=2 {
						fmt.Printf("10")
					}
					if w & 0x1 == 0 {
						fmt.Printf("01")

					} else {
						fmt.Printf("1")
					}

				} else {
					fmt.Printf("1")
					for j:=2; j<w; j++ {
						fmt.Printf("0")
					}
					fmt.Printf("1")
				}

			} else {
				if i == h && i & 0x1 == 0 && h > 4 {
					fmt.Printf("00")
					for j:=1; j<=w-4; j++ {
						if j & 0x1 == 1 {
							fmt.Printf("1")

						} else {
							fmt.Printf("0")
						}
					}
					fmt.Printf("00")
					continue
				}
				for j:=0; j<w; j++ {
					fmt.Printf("0")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var h,w int
		h, input = GetInt(input)
		w, _ = GetInt(input)

		// Solve
		for i:=1; i<=h; i++ {
			if i & 0x1 == 1 {
				if i == 1 || i == h {
					for j:=1; j<w-1; j+=2 {
						fmt.Printf("10")
					}
					if w & 0x1 == 0 {
						fmt.Printf("01")

					} else {
						fmt.Printf("1")
					}

				} else {
					fmt.Printf("1")
					for j:=2; j<w; j++ {
						fmt.Printf("0")
					}
					fmt.Printf("1")
				}

			} else {
				for j:=0; j<w; j++ {
					fmt.Printf("0")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    input, _ := reader.ReadString('\n')

	// Get t
	t, _ := GetInt(input)

	for i:=0; i<t; i++ {
		// Get n
		input, _ = reader.ReadString('\n')
		var h,w int
		h, input = GetInt(input)
		w, _ = GetInt(input)

		// Solve
		for i:=1; i<=h; i++ {
			if i & 0x1 == 1 {
				if i == 1 || i == h {
					for j:=1; j<w-1; j+=2 {
						fmt.Printf("1 0 ")
					}
					if w & 0x1 == 0 {
						fmt.Printf("0 1")

					} else {
						fmt.Printf("1")
					}

				} else {
					fmt.Printf("1 ")
					for j:=2; j<w; j++ {
						fmt.Printf("0 ")
					}
					fmt.Printf("1")
				}

			} else {
				for j:=0; j<w; j++ {
					fmt.Printf("0 ")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, r, c := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &r, &c)
		o := make([][]int, r)
		for j := 0; j < r; j++ {
			o[j] = make([]int, c)
			if j&1 == 1 {
				continue
			}
			for k := 0; k < c; k++ {
				if k&1 == 0 && (j == 0 || j == r-1) {
					o[j][k] = 1
				} else if 0 < j && j < r-1 && (k == 0 || k == c-1) {
					o[j][k] = 1
				}
			}
		}
		for j := 0; j < r; j++ {
			for k := 0; k < c; k++ {
				fmt.Fprint(w, o[j][k])
			}
			fmt.Fprintln(w, "")
		}
		fmt.Fprintln(w, " ")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var height, width int
	fmt.Fscan(in, &height)
	fmt.Fscan(in, &width)
	var matrix = make([][]int, height)
	for i := 0; i < height; i++ {
		matrix[i] = make([]int, width)
	}
	top := 0
	bottom := len(matrix) - 1
	right := 0
	left := len(matrix[0]) - 1
	for i := 0; i < len(matrix[0]); i++ {
		if canput(top, i, matrix) {
			matrix[0][i] = 1
		}
	}
	for i := 0; i < len(matrix[0]); i++ {
		if canput(bottom, i, matrix) {
			matrix[bottom][i] = 1
		}
	}

	for i := 0; i < len(matrix); i++ {
		if canput(i, right, matrix) {
			matrix[i][right] = 1
		}
	}

	for i := 0; i < len(matrix); i++ {
		if canput(i, left, matrix) {
			matrix[i][left] = 1
		}
	}
	for i := 0; i < len(matrix); i++ {
		for j := 0; j < len(matrix[0]); j++ {
			fmt.Print(matrix[i][j], " ")
		}
		fmt.Println()
	}
	fmt.Println()
}

func canput(currentX int, currentY int, matrix [][]int) bool {
	if currentX-1 >= 0 {
		tempX := currentX - 1
		if matrix[tempX][currentY] == 1 {
			return false
		}
		if currentY-1 >= 0 && matrix[tempX][currentY-1] == 1 {
			return false
		}
		if currentY+1 < len(matrix[0]) && matrix[tempX][currentY+1] == 1 {
			return false
		}

	}
	if currentX+1 < len(matrix) {
		tempX := currentX + 1
		if matrix[tempX][currentY] == 1 {
			return false
		}
		if currentY-1 >= 0 && matrix[tempX][currentY-1] == 1 {
			return false
		}
		if currentY+1 < len(matrix[0]) && matrix[tempX][currentY+1] == 1 {
			return false
		}
	}
	if currentY-1 >= 0 {
		if matrix[currentX][currentY-1] == 1 {
			return false
		}
	}
	if currentY+1 < len(matrix[0]) && matrix[currentX][currentY+1] == 1 {
		return false
	}
	return true
}


During the hypnosis session, Nicholas suddenly remembered a positive integer $$$n$$$, which doesn't contain zeros in decimal notation. Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or equal to one?For some numbers doing so is impossible: for example, for number $$$53$$$ it's impossible to delete some of its digits to obtain a not prime integer. However, for all $$$n$$$ in the test cases of this problem, it's guaranteed that it's possible to delete some of their digits to obtain a not prime number.Note that you cannot remove all the digits from the number.A prime number is a number that has no divisors except one and itself. A composite is a number that has more than two divisors. $$$1$$$ is neither a prime nor a composite number.

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$k$$$ ($$$1 \le k \le 50$$$) — the number of digits in the number. The second line of each test case contains a positive integer $$$n$$$, which doesn't contain zeros in decimal notation ($$$10^{k-1} \le n < 10^{k}$$$). It is guaranteed that it is always possible to remove less than $$$k$$$ digits to make the number not prime. It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$10^4$$$.

For every test case, print two numbers in two lines. In the first line print the number of digits, that you have left in the number. In the second line print the digits left after all delitions.  If there are multiple solutions, print any.

NoteIn the first test case, you can't delete $$$2$$$ digits from the number $$$237$$$, as all the numbers $$$2$$$, $$$3$$$, and $$$7$$$ are prime. However, you can delete $$$1$$$ digit, obtaining a number $$$27 = 3^3$$$.In the second test case, you can delete all digits except one, as $$$4 = 2^2$$$ is a composite number.

package main

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

func sieve(isPrime []bool) {
	n := 10001

	for i := 0; i < n; i++ {
		isPrime[i] = true
	}
	for i := 2; i < n; i++ {
		if isPrime[i] {
			for j := i * i; j < n; j += i {
				isPrime[j] = false
			}
		}
	}
}

var best, bestNum int

func gen(s string, i int, num int, k int, isPrime []bool) {
	if k >= best {
		return
	}
	if !isPrime[num] {
		best, bestNum = k, num
		return
	}

	for j := i; j < len(s); j++ {
		gen(s, j+1, num*10+int(s[j]-'0'), k+1, isPrime)
	}
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var isPrime = make([]bool, 100001)
	sieve(isPrime)
	isPrime[1] = false

	var T int
	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n int
		s := ""
		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fscanf(r, "%s\n", &s)
		best = 5
		bestNum = 0

		gen(s, 0, 0, 0, isPrime)

		fmt.Println(best)
		fmt.Println(bestNum)
	}
}

package main

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

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

	notPrime := make([]bool, 15)
	notPrime[1] = true
	for i := 2; i < len(notPrime); i++ {
		if !notPrime[i] {
			for j := 2 * i; j < len(notPrime); j += i {
				notPrime[j] = true
			}
		}
	}
	table := map[int][]int{
		2 : []int{2, 5, 7},
		3 : []int{3, 5, 2},
		5 : []int{5, 2, 7},
		7 : []int{7, 5, 2},
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int
		var n string
		Fscan(in, &k, &n)

		solve := func() {
			for _, c := range n {
				if notPrime[int(c - '0')] {
					Fprintln(out, 1)
					Fprintln(out, string(c))
					return
				}
			}
			for i := 0; i < len(n); i++ {
				for j := i+1; j < len(n); j++ {
					for _, val := range table[int(n[i] - '0')] {
						if val == int(n[j] - '0') {
							Fprintln(out, 2)
							Fprint(out, string(n[i]), val, "\n")
							return
						}
					}
				}
			}
		}
		solve()
	}
}

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

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

package main

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

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

	notPrime := make([]bool, 1000005)
	notPrime[1] = true
	for i := 2; i < len(notPrime); i++ {
		if !notPrime[i] {
			for j := 2 * i; j < len(notPrime); j += i {
				notPrime[j] = true
			}
		}
	}
	table := map[int][]int{
		2 : []int{2, 5, 7},
		3 : []int{3, 5, 2},
		5 : []int{5, 2, 7},
		7 : []int{7, 5, 2},
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int
		var n string
		Fscan(in, &k, &n)

		solve := func() {
			for _, c := range n {
				if notPrime[int(c - '0')] {
					Fprintln(out, 1)
					Fprintln(out, string(c))
					return
				}
			}
			for i := 0; i < len(n); i++ {
				for j := i+1; j < len(n); j++ {
					for _, val := range table[int(n[i] - '0')] {
						if val == int(n[j] - '0') {
							Fprintln(out, 2)
							Fprint(out, string(n[i]), val, "\n")
							return
						}
					}
				}
			}
		}
		solve()
	}
}

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

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

// 00
package main

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

type Anything interface {
	int64 | float64 | int | string | float32 | byte
}

func write[K Anything](f *bufio.Writer, a K) {
	f.Write([]byte(fmt.Sprint(a)))
}

func print_two(f *bufio.Writer, n1 int, n2 int) {
	write(f, n1)
	write(f, "\n")
	write(f, n2)
	write(f, "\n")
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var k int
		var s string
		fmt.Fscan(reader, &k, &s)
		m := map[byte]bool{'1': true, '4': true, '6': true, '8': true, '9': true}
		found_two := false
		found_three := false
		found_five := false
		found_seven := false
		ok := false
		for i := 0; i < k; i++ {
			if m[s[i]] {
				ok = true
				print_two(f, 1, int(s[i]-'0'))
				break
			}
		}
		if !ok {

			for i := 0; i < k; i++ {
				if found_two {
					if s[i] == '5' {
						print_two(f, 2, 25)
						break
					}
					if s[i] == '2' {
						print_two(f, 2, 22)
						break
					}
					if s[i] == '7' {
						print_two(f, 2, 27)
						break
					}
				}
				if found_three {
					if s[i] == '2' {
						print_two(f, 2, 32)
						break
					}
					if s[i] == '3' {
						print_two(f, 2, 33)
						break
					}
					if s[i] == '5' {
						print_two(f, 2, 35)
						break
					}

				}
				if found_five {
					if s[i] == '2' {
						print_two(f, 2, 52)
						break
					}
					if s[i] == '5' {
						print_two(f, 2, 55)
						break
					}
					if s[i] == '7' {
						print_two(f, 2, 57)
						break
					}
				}
				if found_seven {
					if s[i] == '2' {
						print_two(f, 2, 72)
						break
					}
					if s[i] == '5' {
						print_two(f, 2, 75)
						break
					}
					if s[i] == '7' {
						print_two(f, 2, 77)
						break
					}
				}
				if s[i] == '2' {
					found_two = true
				}
				if s[i] == '3' {
					found_three = true
				}
				if s[i] == '5' {
					found_five = true
				}
				if s[i] == '7' {
					found_seven = true
				}
			}
		}
	}
}

package main

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

func IsPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return n != 1
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s, found := 0, "", true
		fmt.Fscan(f, &n, &s)
		for j := 0; j < n; j++ {
			p, _ := strconv.Atoi(string(s[j]))
			if !IsPrime(p) {
				fmt.Fprintln(w, 1)
				fmt.Fprintln(w, p)
				found = false
				break
			}
		}
		if found {
			ok := false
			for j := 0; j < n; j++ {
				for k := j + 1; k < n; k++ {
					a, _ := strconv.Atoi(string(s[j]) + string(s[k]))
					if !IsPrime(a) {
						fmt.Fprintln(w, 2)
						fmt.Fprintln(w, a)
						ok = true
						break
					}
				}
				if ok {
					break
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		var num string
		fmt.Scan(&a, &num)
		iszhi(num)
	}
}

func iszhi(n string) {
	t := n
	dd := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
		41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
	arr := map[int]bool{}
	for _, v := range dd {
		arr[v] = true
	}
	str := []byte(t)
	//一位数的时候
	for _, v := range str {

		if !arr[int(v-'0')] {
			fmt.Println("1")
			fmt.Println(v - '0')
			return
		}
	}
	//两位数的时候

	// fmt.Println(str)
	for i := 0; i+1 < len(str); i++ {
		for j := i + 1; j < len(str); j++ {
			s := string(str[i]) + string(str[j])
			num, _ := strconv.Atoi(s)
			if !arr[num] {
				fmt.Println("2")
				fmt.Println(num)
				return
			}
		}
	}
}

package main

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

var p []uint64

var mp map[int]bool

func main() {

	r := bufio.NewReader(os.Stdin)

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

	mp = make(map[int]bool)

	p = Primes(10000)
	for i := 0; i < len(p); i++ {
		mp[int(p[i])] = true
	}

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

		var s string
		fmt.Fscan(r, &s)

		f1, f2 := solve(k, s)
		fmt.Println(f1)
		fmt.Println(f2)
	}
}

func solve(k int, s string) (int, int) {

	for i := 0; i < len(s); i++ {
		d, _ := strconv.Atoi(string(s[i]))

		if _, ok := mp[d]; ok {
			continue
		}
		return 1, d
	}

	for i := 0; i < len(s); i++ {
		for j := i + 1; j < len(s); j++ {
			v := string(s[i]) + string(s[j])
			d, _ := strconv.Atoi(v)

			if _, ok := mp[d]; ok {
				continue
			}
			return 2, d

		}
	}

	for i := 0; i < len(s); i++ {
		for j := i + 1; j < len(s); j++ {
			for k := j + 1; k < len(s); k++ {
				v := string(s[i]) + string(s[j]) + string(k)
				d, _ := strconv.Atoi(v)

				if _, ok := mp[d]; ok {
					continue
				}
				return 3, d
			}
		}
	}
	return -1, -1
}

func fill(nums []bool, i uint64, max uint64) {
	a := 3 * i
	for a <= max {
		nums[a/2] = true
		a = a + 2*i
	}
}

func goFill(nums []bool, i uint64, max uint64, next chan bool) {
	fill(nums, i, max)
	<-next
}

// SieveOfEratosthenes returns a slice of all prime numbers equal or lower than max using Sieve Of Eratosthenes.
// This is without segmenting.
func SieveOfEratosthenes(n uint64) []uint64 {
	cores := runtime.NumCPU()
	next := make(chan bool, cores)

	var nums = make([]bool, n/2+1)
	m := uint64(math.Sqrt(float64(n)))

	for i := uint64(3); i <= m; i = i + 2 {
		if nums[i/2] == false {
			go goFill(nums, i, n, next)
			next <- true
		}
	}

	for i := 0; i < cores; i++ {
		next <- true
	}

	var ps []uint64
	if n >= 2 {
		ps = append(ps, 2)
	}
	for i := uint64(3); i <= n; i = i + 2 {
		if nums[i/2] == false {
			ps = append(ps, i)
		}
	}
	return ps
}

var csegPool sync.Pool

func fillSegments(n uint64, basePrimes []uint64, allPrimes *[]uint64, segSize uint64, segNum uint64, next chan bool, nextTurn []chan bool) {
	cseg := (csegPool.Get()).([]bool)
	for i := uint64(0); i < segSize; i++ {
		cseg[i] = false
	}
	for i := 0; i < len(basePrimes); i++ {
		jMax := segSize * (segNum + 1) / basePrimes[i]
		for j := (segSize * segNum) / basePrimes[i]; j < jMax; j++ {
			sn := (j + 1) * basePrimes[i]
			cseg[sn-segSize*segNum-1] = true
		}
	}

	// This waiting for turn is to avoid sorts at the end.
	// Sorts are much more expensive than this wait even for a
	// mostly sorted list.
	if segNum > 1 {
		<-nextTurn[segNum]
	}

	for i := uint64(0); i < segSize; i++ {
		if !cseg[i] && segSize*segNum+i+1 <= n {
			*allPrimes = append(*allPrimes, segSize*segNum+i+1)
		}
	}

	<-next
	if int(segNum)+1 < len(nextTurn) {
		nextTurn[segNum+1] <- true
	}

	csegPool.Put(cseg)
}

// Primes is using Segmented sieve. This method will reduce memory usae of Sieve of Eratosthenes considerably.
// besides memory allocation for Prime numbers slice, there is only O(sqrt(n)) extra memory required for the operation
// You can learn more about it in https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes.
func Primes(n uint64) (allPrimes []uint64) {
	if uint64(math.Log(float64(n))-1) == 0 {
		return SieveOfEratosthenes(n)
	}

	// There is a function pi(x) in math that will returns approximate number of prime numbers below n.
	allPrimes = make([]uint64, 0, n/uint64(math.Log(float64(n))-1))
	segSize := uint64(math.Sqrt(float64(n)))

	csegPool.New = func() interface{} {
		return make([]bool, segSize)
	}

	basePrimes := SieveOfEratosthenes(segSize)
	allPrimes = append(allPrimes, basePrimes...)

	cores := runtime.NumCPU()
	next := make(chan bool, cores)
	var nextTurn []chan bool
	nextTurn = make([]chan bool, n/segSize+1)
	for i := uint64(0); i < n/segSize+1; i++ {
		nextTurn[i] = make(chan bool)
	}
	for segNum := uint64(1); segNum <= n/segSize; segNum++ {
		go fillSegments(n, basePrimes, &allPrimes, segSize, segNum, next, nextTurn)
		next <- true
	}
	for i := 0; i < cores; i++ {
		next <- true
	}

	return allPrimes
}

package main

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var k int
		fmt.Fscan(input, &k)
		ARR := make([]int, 10)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		for i := 0; i < k; i++ {
			q := int(STRING[i]) - 48
			ARR[q]++
		}
		if ARR[1] != 0 {
			fmt.Println(1)
			fmt.Println(1)
		} else {

			if ARR[4] != 0 {
				fmt.Println(1)
				fmt.Println(4)
			} else {
				if ARR[6] != 0 {
					fmt.Println(1)
					fmt.Println(6)
				} else {
					if ARR[8] != 0 {
						fmt.Println(1)
						fmt.Println(8)
					} else {
						if ARR[9] != 0 {
							fmt.Println(1)
							fmt.Println(9)
						} else {
							r := 0
							for i := 2; i < 8; i++ {
								if ARR[i] > 1 {
									e := 11 * i
									fmt.Println(2)
									fmt.Println(e)
									r = 1
									break

								}
							}
							if r == 0 {
								if k == 2 {
									fmt.Println(2)
									fmt.Println(string(STRING))
								} else {
									fmt.Println(2)
									if string(STRING[0]) == "2" {
										for i := 5; i < 8; {
											if ARR[i] != 0 {
												e := 20 + i
												fmt.Println(e)
												break
											}
											i = i + 2
										}
									}

									if string(STRING[0]) == "3" {
										for i := 2; i < 6; {
											if ARR[i] != 0 {
												e := 30 + i
												fmt.Println(e)
												break
											}
											i = i + 3
										}
									}

									if string(STRING[0]) == "5" {
										for i := 2; i < 8; {
											if ARR[i] != 0 {
												e := 50 + i
												fmt.Println(e)
												break
											}
											i = i + 5
										}
									}
									if string(STRING[0]) == "7" {
										for i := 2; i < 6; {
											if ARR[i] != 0 {
												e := 70 + i
												fmt.Println(e)
												break
											}
											i = i + 3
										}
									}

								}

							}

						}
					}
				}

			}
		}

	}
}

package main

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

func ScenesFromAMemory() {
	sc := bufio.NewScanner(os.Stdin)
	for tcs := ScanPosInt(sc); tcs > 0; tcs-- { // 1 <= tcs <= 1E3
		k := ScanPosInt(sc) // k  (1≤k≤50) the number of digits in the number.
		// positive integer n, which doesn't contain zeros in decimal notation (10^k−1≤n<10^k) (what's the point?)
		// It is guaranteed that it is always possible to remove less than k digits to make the number not prime.
		sc.Scan()
		nString := sc.Text()
		// max number of digits that can be removed to obtain a non-prime
		digits := make([]int, k)
		for i := range digits {
			digits[i] = int(nString[i] - '0')
		}
		for i := 1; i <= k; i++ {
			b := SubInts(digits, i, func(ds []int) bool {
				d := IntOfDigits(ds)
				if !IsPrime(d) {
					fmt.Println(i)
					fmt.Println(d)
					return true
				}
				return false
			})
			if b {
				break
			}
		}
	}
}

func main() {
	ScenesFromAMemory()
}

func ScanPosInt(scanner *bufio.Scanner) (n int) {
	scanner.Scan()
	buf := scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func IsPrime(x int) bool {
	return big.NewInt(int64(x)).ProbablyPrime(0)
}

func IntOfDigits(d []int) int {
	result := 0
	pow := 1
	for i := len(d) - 1; i >= 0; i-- {
		result += d[i] * pow
		pow *= 10
	}
	return result
}

func SubInts(xs []int, n int, f func([]int) bool) bool {
	var subInts func(xs, ints []int, n int, f func([]int) bool) bool
	subInts = func(xs, ints []int, n int, f func([]int) bool) bool {
		if n == 0 {
			return f(ints)
		}
		for i := 0; i < len(xs); i++ {
			ints = append(ints, xs[i])
			b := subInts(xs[i+1:], ints, n-1, f)
			if b {
				return true // stop
			}
			ints = ints[:len(ints)-1]
		}
		return false
	}
	ints := make([]int, 0, len(xs))
	return subInts(xs, ints, n, f)
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func isPrime(num int) bool {
	if num < 2 {
		return true
	}

	for i := 2; int64(i) * int64(i) <= int64(num); i++ {
		if num % i == 0 {
			return false
		}
	}
	return true
}

func buildNum(mask int, b []byte) (int, int) {
	num := 0
	digits := 0

	for i := 0; i < len(b); i++ {
		if (mask & (1 << i)) > 0 {
			num = num * 10 + int(b[i] - '0')
			digits += 1
		}
	}
	return num, digits
}

func solve(w string) string {
	bw := []byte(w)
	count := make(map[byte]int)
	for _, ch := range bw {
		count[ch]++
	}

	if count['1'] > 0 {
		return "1"
	}
	if count['4'] > 0 {
		return "4"
	}
	if count['6'] > 0 {
		return "6"
	}
	if count['8'] > 0 {
		return "8"
	}
	if count['9'] > 0 {
		return "9"
	}
	if count['2'] > 1 {
		return "22"
	}
	if count['3'] > 1 {
		return "33"
	}
	if count['5'] > 1 {
		return "55"
	}
	if count['7'] > 1 {
		return "77"
	}
	if count['5'] > 0 && bw[0] != '5' {
		return string(bw[0]) + "5"
	}

	res := w
	for i := 1; i < (1 << len(bw)); i++ {
		num, digits := buildNum(i, bw)
		if !isPrime(num) && digits < len(res) {
			res = fmt.Sprintf("%v", num)
		}
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		_, w := stdin.Int(), stdin.Word()
		res := solve(w)
		fmt.Println(len(res))
		fmt.Println(res)
	}
}

package main

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

func sieve(isPrime []bool) {
	n := len(isPrime)

	for i := 0; i < n; i++ {
		isPrime[i] = true
	}
	for i := 2; i < n; i++ {
		if isPrime[i] {
			for j := i * i; j < n; j += i {
				isPrime[j] = false
			}
		}
	}
}

var best, bestNum int

func gen(s string, i int, num int, k int, isPrime []bool) {
	if k >= best {
		return
	}
	if !isPrime[num] {
		best, bestNum = k, num
		return
	}

	for j := i; j < len(s); j++ {
		gen(s, j+1, num*10+int(s[j]-'0'), k+1, isPrime)
	}
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var isPrime = make([]bool, 100001)
	//sieve(isPrime)
	isPrime[1] = false

	var T int
	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n int
		s := ""
		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fscanf(r, "%s\n", &s)
		best = 5
		bestNum = 0

		gen(s, 0, 0, 0, isPrime)

		fmt.Println(best)
		fmt.Println(bestNum)
	}
}

package main

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

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

	notPrime := make([]bool, 1000005)
	notPrime[1] = true
	for i := 2; i < len(notPrime); i++ {
		if !notPrime[i] {
			for j := 2 * i; j < len(notPrime); j += i {
				notPrime[j] = true
			}
		}
	}
	table := map[int][]int{
		2 : []int{2, 5, 7},
		3 : []int{3, 5, 2},
		5 : []int{5, 2, 7},
		7 : []int{7, 5, 2},
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int
		var n string
		Fscan(in, &k, &n)

		solve := func() {
			for _, c := range n {
				if notPrime[int(c - '0')] {
					Fprintln(out, 1)
					Fprintln(out, string(c))
					return
				}
			}
			for i := 1; i < len(n); i++ {
				for _, val := range table[int(n[0] - '0')] {
					if val == int(n[i] - '0') {
						Fprintln(out, 2)
						Fprint(out, string(n[0]), val, "\n")
						return
					}
				}
			}
		}
		solve()
	}
}

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

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

package main

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

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

	notPrime := make([]bool, 1000005)
	notPrime[1] = true
	for i := 2; i < len(notPrime); i++ {
		if !notPrime[i] {
			for j := 2 * i; j < len(notPrime); j += i {
				notPrime[j] = true
			}
		}
	}
	table := map[int][]int{
		2 : []int{2, 5, 7},
		3 : []int{3, 5, 2},
		5 : []int{5, 2, 7},
		7 : []int{7, 5, 2},
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int
		var n string
		Fscan(in, &k, &n)

		solve := func() {
			for _, c := range n {
				if notPrime[int(c - '0')] {
					Fprintln(out, 1)
					Fprintln(out, string(c))
					return
				}
			}
			for i := 1; i < len(n); i++ {
				for _, val := range table[int(n[0] - '0')] {
					if val == int(n[i] - '0') {
						Fprintln(out, 2)
						Fprint(out, string(n[0]), val, "\n")
					}
				}
			}
		}
		solve()
	}
}

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

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

// 00
package main

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

type Anything interface {
	int64 | float64 | int | string | float32 | byte
}

func write[K Anything](f *bufio.Writer, a K) {
	f.Write([]byte(fmt.Sprint(a)))
}

func print_two(f *bufio.Writer, n1 int, n2 int) {
	write(f, n1)
	write(f, "\n")
	write(f, n2)
	write(f, "\n")
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var k int
		var s string
		fmt.Fscan(reader, &k, &s)
		m := map[byte]bool{'1': true, '4': true, '6': true, '8': true, '9': true}
		found_two := false
		found_three := false
		found_five := false
		found_seven := false
		for i := 0; i < k; i++ {
			if m[s[i]] {
				print_two(f, 1, int(s[i]-'0'))
				break
			}
			if found_two {
				if s[i] == '5' {
					print_two(f, 2, 25)
					break
				}
				if s[i] == '2' {
					print_two(f, 2, 22)
					break
				}
				if s[i] == '7' {
					print_two(f, 2, 27)
					break
				}
			}
			if found_three {
				if s[i] == '2' {
					print_two(f, 2, 32)
					break
				}
				if s[i] == '3' {
					print_two(f, 2, 33)
					break
				}
				if s[i] == '5' {
					print_two(f, 2, 35)
					break
				}

			}
			if found_five {
				if s[i] == '2' {
					print_two(f, 2, 52)
					break
				}
				if s[i] == '5' {
					print_two(f, 2, 55)
					break
				}
				if s[i] == '7' {
					print_two(f, 2, 57)
					break
				}
			}
			if found_seven {
				if s[i] == '2' {
					print_two(f, 2, 72)
					break
				}
				if s[i] == '5' {
					print_two(f, 2, 75)
					break
				}
				if s[i] == '7' {
					print_two(f, 2, 77)
					break
				}
			}
			if s[i] == '2' {
				found_two = true
			}
			if s[i] == '3' {
				found_three = true
			}
			if s[i] == '5' {
				found_five = true
			}
			if s[i] == '7' {
				found_seven = true
			}
		}

	}
}

package main

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

func IsPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return n != 1
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s, found, o := 0, "", true, map[int]int{}
		fmt.Fscan(f, &n, &s)
		for j := 0; j < n; j++ {
			p, _ := strconv.Atoi(string(s[j]))
			if !IsPrime(p) {
				fmt.Fprintln(w, 1)
				fmt.Fprintln(w, p)
				found = false
				break
			} else {
				o[p]++
			}
		}
		if found {
			ok := false
			for k, v := range o {
				if v > 1 {
					fmt.Fprintln(w, 2)
					fmt.Fprintln(w, k*10+k)
					ok = true
				}
			}
			if !ok {
				fmt.Fprintln(w, len(s))
				fmt.Fprintln(w, s)
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, num int
		fmt.Scan(&a, &num)
		iszhi(num)
	}
}

func iszhi(n int) {
	t := n
	dd := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
		41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
	arr := map[int]bool{}
	for _, v := range dd {
		arr[v] = true
	}
	//一位数的时候
	for n > 0 {
		if n%10 > 2 && !arr[n%10] {
			fmt.Println("1")
			fmt.Println(n % 10)
			return
		}
		n = n / 10
	}

	//两位数的时候
	str := []byte(strconv.Itoa(t))
	// fmt.Println(str)
	for i := 0; i+1 < len(str); i++ {
		for j := i + 1; j < len(str); j++ {
			s := string(str[i]) + string(str[j])
			num, _ := strconv.Atoi(s)
			if !arr[num] {
				fmt.Println("2")
				fmt.Println(num)
				return
			}
		}
	}
}


Let's call the following process a transformation of a sequence of length $$$n$$$.If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of $$$n$$$ integers: the greatest common divisors of all the elements in the sequence before each deletion.You are given an integer sequence $$$1, 2, \dots, n$$$. Find the lexicographically maximum result of its transformation.A sequence $$$a_1, a_2, \ldots, a_n$$$ is lexicographically larger than a sequence $$$b_1, b_2, \ldots, b_n$$$, if there is an index $$$i$$$ such that $$$a_j = b_j$$$ for all $$$j < i$$$, and $$$a_i > b_i$$$.

The first and only line of input contains one integer $$$n$$$ ($$$1\le n\le 10^6$$$).

Output $$$n$$$ integers  — the lexicographically maximum result of the transformation.

NoteIn the first sample the answer may be achieved this way:  Append GCD$$$(1, 2, 3) = 1$$$, remove $$$2$$$.  Append GCD$$$(1, 3) = 1$$$, remove $$$1$$$.  Append GCD$$$(3) = 3$$$, remove $$$3$$$. We get the sequence $$$[1, 1, 3]$$$ as the result.

package main

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

var out = bufio.NewWriter(os.Stdout)

func run(c, n int) {
	switch (n) {
	case 1:
		fmt.Fprintln(out, c)
	case 2:
		fmt.Fprintln(out, c, 2*c)
	case 3:
		fmt.Fprintln(out, c, c, 3*c)
	default:
		for i := n - n/2; i > 0; i-- {
			fmt.Fprintf(out, "%d ", c)
		}
		run(2*c, n/2)
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	run(1, n)
	out.Flush()
}

package main

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

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

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

var seqN int

func printGcds(base, n int) {
	if n == 1 {
		printf("%d\n", base*1)
		return
	} else if n == 2 {
		printf("%d\n%d\n", base, base*2)
		return
	} else if n == 3 {
		printf("%d\n%d\n%d\n", base, base, base*3)
		return
	}
	for i := 0; i < ((n + 1) / 2); i++ {
		printf("%d\n", base)
	}
	printGcds(base*2, n/2)
}

func main() {
	defer writer.Flush()
	scanf("%d", &seqN)

	printGcds(1, seqN)
}

package main

import (
	"bytes"
	"fmt"
	"strconv"
)

func main() {
	n := 0
	fmt.Scan(&n)
	res, level := []int{}, 1

	for n > 0 {
		if n == 3 {
			res = append(res, []int{level, level, level * 3}...)
			break
		}
		reduce := 0
		for i := 1; i <= n; i++ {
			if i%2 == 1 {
				res, reduce = append(res, level), reduce+1
			}
		}
		n, level = n-reduce, level*2
	}

	buffer := []byte{}
	output := bytes.NewBuffer(buffer)
	output.WriteString(strconv.Itoa(res[0]))

	for i := 1; i < len(res); i++ {
		output.WriteString(" " + strconv.Itoa(res[i]))
	}

	fmt.Println(output.String())
}

package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 3 {
		fmt.Println("1 1 3")
		os.Exit(0)
	}

	res, twoCounter := "1", n/2
	for i := 1; i < (n - twoCounter); i++ {
		res += " 1"
	}
	for i := 0; i < twoCounter; i++ {
		res += " 2"
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"os"
)

func main() {
	n := 0
	fmt.Scan(&n)
	if n == 3 {
		fmt.Println("1 1 3")
		os.Exit(0)
	}

	res, nums := "1", make([]int, n-1)
	for i := 1; i < n; i++ {
		nums[i-1] = i + 1
	}
	level := 1
	for len(nums) > 0 {
		newNums := []int{}
		for _, num := range nums {
			if num%2 == 1 {
				res += fmt.Sprintf(" %d", level)
			} else {
				newNums = append(newNums, num/2)
			}
		}
		nums, level = newNums, level*2
	}
	fmt.Println(res)
}