Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1,   p2,   ...,   pn.Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).

Print n integers forming the permutation. If there are multiple answers, print any of them.

NoteBy |x| we denote the absolute value of number x.

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n := scanInt(scanner)
	k := scanInt(scanner)
	writer.WriteString(fmt.Sprintf("%d", n))
	for i := n-1; i > k; i-- {
		writer.WriteString(fmt.Sprintf(" %d", i))
	}
	x, d := k+1, -k
	for d != 0 {
		x += d
		writer.WriteString(fmt.Sprintf(" %d", x))
		if d < 0 {
			d = -d - 1
		} else {
			d = -d + 1
		}
	}
	writer.WriteString("\n")
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	end := 2 + k
	res := []string{"1"}
	sign := 1
	next := 1
	for ; k > 0; k-- {
		next += sign * k
		sign *= -1
		res = append(res, strconv.Itoa(next))
	}
	for ; end <= n; end++ {
		res = append(res, strconv.Itoa(end))
	}
	fmt.Println(strings.Join(res, " "))
}

package main

import (
	"fmt"
)

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

	last := 1
	for i := k; i > 0; i-- {
		fmt.Printf("%d ", last)
		if last <= (k+1)/2 {
			last = last + i
		} else {
			last = last - i
		}
	}
	fmt.Printf("%d ", last)
	for i := k + 2; i <= n; i++ {
		fmt.Printf("%d ", i)
	}
	fmt.Println()
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"io"
	"math/rand"
	"os"
	"strconv"
	"time"
	"unicode/utf8"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	k := readInt()
	a := 1
	b := n
	for i := 0; i < k; i++ {
		if (i & 1) == 0 {
			printInt(a)
			a++
			printSpace()
		} else {
			printInt(b)
			b--
			printSpace()
		}
	}

	if (k & 1) == 0 {
		for i := 0; i < n - k; i++ {
			printInt(b)
			b--
			printSpace()
		}
	} else {
		for i := 0; i < n - k; i++ {
			printInt(a)
			a++
			printSpace()
		}
	}

	printLine()
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
)

func main() {
	input := os.Stdin
	output := os.Stdout
	//	input, _ := os.Open("")
	//	output, _ := os.Create("")

	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

// Sorting

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	if p[j].a == p[i].a {
		return p[j].b < p[i].b
	} else {
		return p[j].a < p[i].a
	}
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

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

	n := scanInt(scanner)
	k := scanInt(scanner)
	writer.WriteString(fmt.Sprintf("%d", n))
	for i := n-1; i > k; i-- {
		writer.WriteString(fmt.Sprintf(" %d", i))
	}
	x, d := k+1, k
	for d != 0 {
		if x > d {
			x -= d
		} else {
			x += d
		}
		writer.WriteString(fmt.Sprintf(" %d", x))
		d--
	}
	writer.WriteString("\n")
}


One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.

The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.

In the first line print a single real number with exactly one  decimal place — the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.

NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5.

package main

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

type item struct {
	id    int
	price int64
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<16)
	var n, k int
	fmt.Fscan(in, &n, &k)

	var stools, pencils []item
	for i := 1; i <= n; i++ {
		var c int64
		var t int
		fmt.Fscan(in, &c, &t)
		it := item{i, c}
		switch t {
		case 1:
			stools = append(stools, it)
		case 2:
			pencils = append(pencils, it)
		default:
			panic(t)
		}
	}
	sort.Slice(stools, func(i, j int) bool { return stools[i].price > stools[j].price })

	var carts [][]item
	for _, st := range stools {
		if len(carts) < k {
			carts = append(carts, []item{st})
		} else {
			carts[k-1] = append(carts[k-1], st)
		}
	}
	for _, p := range pencils {
		if len(carts) < k {
			carts = append(carts, []item{p})
		} else {
			carts[k-1] = append(carts[k-1], p)
		}
	}

	price := int64(0)
	half := false
	for i, cart := range carts {
		min := cart[0].price
		for _, it := range cart {
			if min > it.price {
				min = it.price
			}
			price += it.price
		}
		if i < len(stools) {
			price -= min / 2
			if min&1 == 1 {
				if half {
					half = false
				} else {
					price--
					half = true
				}
			}
		}
	}

	out := bufio.NewWriterSize(os.Stdout, 1<<16)
	defer out.Flush()
	fmt.Fprint(out, price)
	if half {
		fmt.Fprintln(out, ".5")
	} else {
		fmt.Fprintln(out, ".0")
	}
	for _, cart := range carts {
		fmt.Fprint(out, len(cart))
		for _, it := range cart {
			fmt.Fprint(out, " ", it.id)
		}
		fmt.Fprintln(out)
	}
}


You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$.For each $$$a_i$$$ find its two divisors $$$d_1 > 1$$$ and $$$d_2 > 1$$$ such that $$$\gcd(d_1 + d_2, a_i) = 1$$$ (where $$$\gcd(a, b)$$$ is the greatest common divisor of $$$a$$$ and $$$b$$$) or say that there is no such pair.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the size of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 10^7$$$) — the array $$$a$$$.

To speed up the output, print two lines with $$$n$$$ integers in each line. The $$$i$$$-th integers in the first and second lines should be corresponding divisors $$$d_1 > 1$$$ and $$$d_2 > 1$$$ such that $$$\gcd(d_1 + d_2, a_i) = 1$$$ or $$$-1$$$ and $$$-1$$$ if there is no such pair. If there are multiple answers, print any of them.

NoteLet's look at $$$a_7 = 8$$$. It has $$$3$$$ divisors greater than $$$1$$$: $$$2$$$, $$$4$$$, $$$8$$$. As you can see, the sum of any pair of divisors is divisible by $$$2$$$ as well as $$$a_7$$$.There are other valid pairs of $$$d_1$$$ and $$$d_2$$$ for $$$a_{10}=24$$$, like $$$(3, 4)$$$ or $$$(8, 3)$$$. You can print any of them.

package main

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

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

	n := readNum(reader)
	A := readNNums(reader, n)
	B, C := solve(n, A)

	var buf bytes.Buffer
	var buf2 bytes.Buffer
	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", B[i]))
		buf2.WriteString(fmt.Sprintf("%d ", C[i]))
	}
	fmt.Println(buf.String())
	fmt.Println(buf2.String())
}

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

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

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

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

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

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

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

	return i
}

const MAX_A = 10000003

var minDiv [MAX_A]int

func init() {
	for x := 2; x < MAX_A; x++ {
		if minDiv[x] == 0 {
			for y := x; y < MAX_A; y += x {
				if minDiv[y] == 0 {
					minDiv[y] = x
				}
			}
		}
	}
}

func solve(n int, A []int) ([]int, []int) {
	B := make([]int, n)
	C := make([]int, n)

	for i := 0; i < n; i++ {
		fs := make(map[int]int)

		num := A[i]

		for num > 1 {
			x := minDiv[num]
			fs[x]++
			num /= x
		}
		if len(fs) == 1 {
			B[i] = -1
			C[i] = -1
			continue
		}
		for k := range fs {
			if B[i] == 0 {
				B[i] = k
				C[i] = 1
			} else {
				C[i] *= k
			}
		}
	}
	return B, C
}

package main

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

func main() {
	defer w.Flush()
	ans := solve(nextInts(nextInt()))
	for i := 0; i < len(ans); i++ {
		Printf("%d ", ans[i][0])
	}
	for i := 0; i < len(ans); i++ {
		Printf("%d ", ans[i][1])
	}
}

func solve(As []int) [][]int {
	ans := [][]int{}
	isPrime, primes := Sieve(1e7)
	for i := 0; i < len(As); i++ {
		x, y := solve1(isPrime, primes, As[i])
		ans = append(ans, []int{x, y})
	}
	return ans
}

func solve1(isPrime []bool, primes []int, n int) (int, int) {
	if isPrime[n] {
		return -1, -1
	}
	for _, prime := range primes {
		if prime >= n {
			return -1, -1
		}
		if n%prime != 0 {
			continue
		}
		for n%prime == 0 {
			n /= prime
		}
		if n == 1 {
			return -1, -1
		}
		return prime, n
	}
	return -1, -1
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var w = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) {
	fmt.Fprintf(w, format, a...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

package main

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

func main() {
	defer w.Flush()

	n := nextInt()
	ans := solve(nextInts(n))

	for i := 0; i < len(ans); i++ {
		Printf("%d ", ans[i][0])
		// if i == len(ans)-1 {
		// 	Printf("%d\n", ans[i][0])
		// } else {
		// 	Printf("%d ", ans[i][0])
		// }
	}
	for i := 0; i < len(ans); i++ {
		Printf("%d ", ans[i][1])
		// if i == len(ans)-1 {
		// 	Printf("%d\n", ans[i][1])
		// } else {
		//
		// }
	}
}

var w = bufio.NewWriter(os.Stdout)

func Printf(format string, a ...interface{}) {
	fmt.Fprintf(w, format, a...)
}

func Println(a ...interface{}) {
	fmt.Fprintln(w, a...)
}

func solve(As []int) [][]int {
	ans := [][]int{}
	isPrime, primes := Sieve(1e7)
	for i := 0; i < len(As); i++ {
		x, y := solve1(isPrime, primes, As[i])
		ans = append(ans, []int{x, y})
	}
	return ans
}

func solve1(isPrime []bool, primes []int, n int) (int, int) {
	if isPrime[n] {
		return -1, -1
	}
	for _, prime := range primes {
		if prime >= n {
			return -1, -1
		}
		if n%prime != 0 {
			continue
		}
		for n%prime == 0 {
			n /= prime
		}
		if n == 1 {
			return -1, -1
		}
		return prime, n
	}
	return -1, -1
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var sc = bufio.NewScanner(os.Stdin)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

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

func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt64()
	}
	return ret
}

package main

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

func main() {
	n := nextInt()
	ans := solve(nextInts(n))

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	for i := 0; i < len(ans); i++ {
		if i == len(ans)-1 {
			fmt.Fprintf(w, "%d\n", ans[i][0])
		} else {
			fmt.Fprintf(w, "%d ", ans[i][0])
		}
	}
	for i := 0; i < len(ans); i++ {
		if i == len(ans)-1 {
			fmt.Fprintf(w, "%d\n", ans[i][1])
		} else {
			fmt.Fprintf(w, "%d ", ans[i][1])
		}
	}
}

func solve(As []int) [][]int {
	ans := [][]int{}
	isPrime, primes := Sieve(1e7)
	for i := 0; i < len(As); i++ {
		x, y := solve1(isPrime, primes, As[i])
		ans = append(ans, []int{x, y})
	}
	return ans
}

func solve1(isPrime []bool, primes []int, n int) (int, int) {
	if isPrime[n] {
		return -1, -1
	}
	for _, prime := range primes {
		if prime >= n {
			return -1, -1
		}
		if n%prime != 0 {
			continue
		}
		for n%prime == 0 {
			n /= prime
		}
		if n == 1 {
			return -1, -1
		}
		return prime, n
	}
	return -1, -1
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var sc = bufio.NewScanner(os.Stdin)

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

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

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

func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt64()
	}
	return ret
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	const mx = 1e7
	f := make([]int, mx+1)
	f[1] = 1
	for i := 2; i <= mx; i++ {
		if f[i] == 0 {
			for j := i; j <= mx; j += i {
				if f[j] == 0 {
					f[j] = i
				}
			}
		}
	}

	var n, v int
	Fscan(in, &n)
	a := make([]interface{}, n)
	b := make([]interface{}, n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		p := f[v]
		for v /= p; f[v] == p; v /= p {
		}
		if v > 1 {
			a[i] = p
			b[i] = v
		} else {
			a[i] = -1
			b[i] = -1
		}
	}
	Fprintln(out, a...)
	Fprintln(out, b...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n := r()
	a := []byte{}
	b := []byte{}
	for i := 0; i < n; i++ {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			a = append(a, strconv.Itoa(p)...)
			a = append(a, ' ')
			b = append(b, strconv.Itoa(w)...)
			b = append(b, ' ')
		} else {
			a = append(a, "-1 "...)
			b = append(b, "-1 "...)
		}
	}
	Fprintf(out, "%s\n%s", a, b)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	var n, v int
	Fscan(in, &n)
	ans := make([]interface{}, n)
	for i := range ans {
		Fscan(in, &v)
		q, s := 0, 1
		for v > 1 {
			p := lpf[v]
			for v /= p; lpf[v] == p; v /= p {
			}
			if q == 0 {
				q = p
			} else {
				s *= p
			}
		}
		if s > 1 {
			Fprint(out, q, " ")
			ans[i] = s
		} else {
			Fprint(out, "-1 ")
			ans[i] = -1
		}
	}
	Fprintln(out)
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n := r()
	a := make([]interface{}, n)
	b := make([]interface{}, n)
	for i := 0; i < n; i++ {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			a[i] = w
			b[i] = v / w
		} else {
			a[i] = -1
			b[i] = -1
		}
	}
	Fprintln(out, a...)
	Fprintln(out, b...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n := r()
	a := make([]interface{}, n)
	b := make([]interface{}, n)
	for i := 0; i < n; i++ {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			a[i] = p
			b[i] = w
		} else {
			a[i] = -1
			b[i] = -1
		}
	}
	Fprintln(out, a...)
	Fprintln(out, b...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	ans := make([]interface{}, r())
	for i := range ans {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			Fprint(out, w, " ")
			ans[i] = v / w
		} else {
			Fprint(out, "-1 ")
			ans[i] = -1
		}
	}
	Fprintln(out)
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	ans := make([]interface{}, r())
	for i := range ans {
		q, s := 0, 1
		for v := r(); v > 1; {
			p := lpf[v]
			for v /= p; lpf[v] == p; v /= p {
			}
			if q == 0 {
				q = p
			} else {
				s *= p
			}
		}
		if s > 1 {
			Fprint(out, q, " ")
			ans[i] = s
		} else {
			Fprint(out, "-1 ")
			ans[i] = -1
		}
	}
	Fprintln(out)
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	ans := make([]int, r())
	for i := range ans {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			Fprint(out, w, " ")
			ans[i] = v / w
		} else {
			Fprint(out, "-1 ")
			ans[i] = -1
		}
	}
	Fprintln(out)
	for _, v := range ans {
		Fprint(out, v, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n := r()
	a := []byte{}
	b := []byte{}
	for i := 0; i < n; i++ {
		v := r()
		p := lpf[v]
		w := v / p
		for ; lpf[w] == p; w /= p {
		}
		if w > 1 {
			x := []byte{}
			for p > 0 {
				x = append(x, byte('0'+p%10))
				p /= 10
			}
			for i := len(x) - 1; i >= 0; i-- {
				a = append(a, x[i])
			}
			a = append(a, ' ')

			x = []byte{}
			for w > 0 {
				x = append(x, byte('0'+w%10))
				w /= 10
			}
			for i := len(x) - 1; i >= 0; i-- {
				b = append(b, x[i])
			}
			b = append(b, ' ')
		} else {
			a = append(a, "-1 "...)
			b = append(b, "-1 "...)
		}
	}
	Fprintf(out, "%s\n%s", a, b)
}

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

package main

import (
	. "fmt"
	"os"
	"strconv"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	a, b := []byte{}, []byte{}
	for n := r(); n > 0; n-- {
		v := r()
		p := lpf[v]
		v /= p
		for ; lpf[v] == p; v /= p {
		}
		if v > 1 {
			a = append(a, strconv.Itoa(p)...)
			a = append(a, ' ')
			b = append(b, strconv.Itoa(v)...)
			b = append(b, ' ')
		} else {
			a = append(a, "-1 "...)
			b = append(b, "-1 "...)
		}
	}
	Printf("%s\n%s", a, b)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	a, b := []byte{}, []byte{}
	for n := r(); n > 0; n-- {
		v := r()
		p := lpf[v]
		v /= p
		for ; lpf[v] == p; v /= p {
		}
		if v > 1 {
			a = append(a, strconv.Itoa(p)...)
			a = append(a, ' ')
			b = append(b, strconv.Itoa(v)...)
			b = append(b, ' ')
		} else {
			a = append(a, "-1 "...)
			b = append(b, "-1 "...)
		}
	}
	out := bufio.NewWriter(os.Stdout)
	Fprintf(out, "%s\n%s", a, b)
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	var n, v int
	Fscan(in, &n)
	ans := make([]interface{}, n)
o:
	for i := range ans {
		Fscan(in, &v)
		q := 0
		for v > 1 {
			p := lpf[v]
			for v /= p; lpf[v] == p; v /= p {
			}
			if q > 0 {
				Fprint(out, q, " ")
				ans[i] = p
				continue o
			}
			q = p
		}
		Fprint(out, "-1 ")
		ans[i] = -1
	}
	Fprintln(out)
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx = 1e7
	lpf := make([]int, mx+1)
	lpf[1] = 1
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	var n, v, p int
	Fscan(in, &n)
	ans := make([]interface{}, n)
	for i := range ans {
		Fscan(in, &v)
		q := 0
		for v > 1 {
			p = lpf[v]
			for v /= p; lpf[v] == p; v /= p {
			}
			if q == 0 {
				q = p
			}
		}
		if p != q {
			Fprint(out, q, " ")
			ans[i] = p
		} else {
			Fprint(out, "-1 ")
			ans[i] = -1
		}
	}
	Fprintln(out)
	Fprint(out, ans...)
}

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


Nezzar loves the game osu!.osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points $$$A,B,C$$$ listed in order, the angle between these three points, centered at $$$B$$$, is strictly less than $$$90$$$ degrees.  Points $$$A,B,C$$$ on the left have angle less than $$$90$$$ degrees, so they can be three consecutive points of a nice beatmap; Points $$$A',B',C'$$$ on the right have angle greater or equal to $$$90$$$ degrees, so they cannot be three consecutive points of a nice beatmap. Now Nezzar has a beatmap of $$$n$$$ distinct points $$$A_1,A_2,\ldots,A_n$$$. Nezzar would like to reorder these $$$n$$$ points so that the resulting beatmap is nice.Formally, you are required to find a permutation $$$p_1,p_2,\ldots,p_n$$$ of integers from $$$1$$$ to $$$n$$$, such that beatmap $$$A_{p_1},A_{p_2},\ldots,A_{p_n}$$$ is nice. If it is impossible, you should determine it.

The first line contains a single integer $$$n$$$ ($$$3 \le n \le 5000$$$). Then $$$n$$$ lines follow, $$$i$$$-th of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — coordinates of point $$$A_i$$$. It is guaranteed that all points are distinct.

If there is no solution, print $$$-1$$$. Otherwise, print $$$n$$$ integers, representing a valid permutation $$$p$$$. If there are multiple possible answers, you can print any.

NoteHere is the illustration for the first test:  Please note that the angle between $$$A_1$$$, $$$A_2$$$ and $$$A_5$$$, centered at $$$A_2$$$, is treated as $$$0$$$ degrees. However, angle between $$$A_1$$$, $$$A_5$$$ and $$$A_2$$$, centered at $$$A_5$$$, is treated as $$$180$$$ degrees.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([][2]int64, n)
	for i := range a {
		Fscan(in, &a[i][0], &a[i][1])
	}
	d := func(i, j int) int64 { x, y := a[i][0]-a[j][0], a[i][1]-a[j][1]; return x*x + y*y }
	v := make([]bool, n)
	v[0] = true
	Fprint(out, 1)
	for i, pre := 1, 0; i < n; i++ {
		k := -1
		for j, b := range v {
			if !b && (k < 0 || d(pre, j) > d(pre, k)) {
				k = j
			}
		}
		Fprint(out, " ", k+1)
		v[k] = true
		pre = k
	}
}

package main

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

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

	n := readNum(reader)

	x, y := make([]int, n), make([]int, n)

	for i := 0; i < n; i++ {
		x[i], y[i] = readTwoNums(reader)
	}

	res := solve(n, x, y)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, x, y []int) []int {
	perm := make([]int, n)

	for i := 0; i < n; i++ {
		perm[i] = i
		for j := i; j > 1; j-- {
			if int64(x[perm[j]]-x[perm[j-1]])*int64(x[perm[j-1]]-x[perm[j-2]])+int64(y[perm[j]]-y[perm[j-1]])*int64(y[perm[j-1]]-y[perm[j-2]]) >= 0 {
				perm[j-1], perm[j] = perm[j], perm[j-1]
			} else {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		perm[i]++
	}

	return perm
}

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, 2*n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
		s := int64(0)
		for i := 0; i < 2*n; i += 2 {
			v := (a[i] - s) / int64(2*n-i)
			if a[i] != a[i+1] || a[i] <= s || (a[i]-s)%int64(2*n-i) > 0 || i > 0 && v >= a[i-2] {
				Fprintln(out, "NO")
				continue o
			}
			a[i] = v
			s += v * 2
		}
		Fprintln(out, "YES")
	}
}

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


Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.

The first line contains integer n (1 ≤ n ≤ 103) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≤ idi ≤ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way.

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.

NoteIn the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.In the second test sample the described situation is impossible as conferences aren't allowed.

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
)

func main() {

	var n,x int
	ans:=0
	flag:=false
	fmt.Scan(&n)
	m := make(map[int]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		if x!=0 {
			m[x]++
			if m[x]==2 {
				ans++
			}
			if m[x]==3 {
				fmt.Println("-1")
				flag=true
				break
			}
		}
	}
	if flag==false {
			fmt.Println(ans)
	}
}

package main

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

func solve() {
	n := readInt()
	m := make(map[int]int)
	cnt := 0
	for i := 0; i < n; i++ {
		t := readInt()
		if t == 0 {
			continue
		}
		m[t] += 1
		if m[t] > 2 {
			fmt.Println(-1)
			return
		}
		if m[t] == 2 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n int = NextInt()
	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var v int = NextInt();
		if v == 0 {
			continue
		}
		if _, exists := mp[v]; !exists {
			mp[v] = 1
		}else {
			mp[v] += 1
			if mp[v] > 2 {
				fmt.Fprintln(out, -1)
				return
			}
		}
	}

	var count int = 0
	for _, value := range mp {
		if value == 2 {
			count++
		}
	}

	fmt.Fprintln(out, count)
}

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

import "fmt"

func main() {
    var n,id int
    call := make(map[int]int)
    fmt.Scan(&n)
    ans, cnt := true, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&id)
        if id != 0 {
            call[id]++
            if call[id] == 2 {
                cnt++
            } else if call[id] > 2 {
                ans = false
            }
        }
    }
    if ans { fmt.Println(cnt) } else { fmt.Println(-1) }
}

package main

import "fmt"

func main() {
	var n, temp int
	fmt.Scan(&n)
	m := make(map[int]int)
	var out int
	for ; n > 0; n-- {
		fmt.Scan(&temp)
		if temp != 0 {
			m[temp]++
			if m[temp] > 2 {
				out = -1
			}
		}
	}
	if out == -1 {
		fmt.Println(-1)
	} else {
		for _, v := range m {
			if v == 2 {
				out++
			}
		}
		fmt.Println(out)
	}
}

package main

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

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

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

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var s int
		fmt.Fscanf(r, "%d", &s)
		if s > 0 {
			mp[s]++
		}
	}

	count := 0
	for _, v := range mp {
		if v > 2 {
			fmt.Println("-1")
			return
		} else if v == 2 {
			count++
		}
	}

	fmt.Println(count)
}

// 291A-mic
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, c, now int
	cou := 1
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.IntSlice(a))
	now = a[0]
	for i := 1; i < n; i++ {
		if now == 0 {
			now = a[i]
			continue
		}
		if now == a[i] {
			cou++
			now = a[i]
		} else {
			cou = 1
			now = a[i]
		}
		if cou == 2 {
			c++
		} else if cou > 2 {
			fmt.Println("-1")
			return
		}
	}
	fmt.Println(c)
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

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

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    m := make(map[int]int)
    for i := 0; i < n; i++ {
        x := nextInt()
        m[x]++
        if x != 0 && m[x] > 2 {
            fmt.Fprintln(out, -1)
            return
        }
    }
    ans := 0
    for k := range m {
        if k != 0 && m[k] == 2 {
            ans++
        }
    }

    fmt.Fprintln(out, ans)

}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
)

func main() {

	var n,x int
	ans:=0
	flag:=false
	fmt.Scan(&n)
	m := make(map[int]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		if x!=0 {
			m[x]++
			if m[x]==2 {
				ans++
			}
			if m[x]==3 {
				fmt.Println("-1")
				flag=true
			}
		}
	}
	if flag==false {
			fmt.Println(ans)
	}
}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
)

func main() {

	var n,x int
	ans:=0
	fmt.Scan(&n)
	m := make(map[int]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		if x!=0 {
			m[x]++
			if m[x]==2 {
				ans++
			}
			if m[x]==3 {
				fmt.Println("-1")
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	var n int = NextInt()
	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var v int = NextInt();
		if _, exists := mp[v]; !exists {
			mp[v] = 1
		}else {
			mp[v] += 1
			if v != 0 && mp[v] > 2 {
				fmt.Fprintln(out, -1)
				return
			}
		}
	}

	var count int = 0
	for _, value := range mp {
		if value == 2 {
			count++
		}
	}

	fmt.Fprintln(out, count)
}

func Next() string{
	if !in.Scan() {
		panic("Scan error")
	}
	return in.Text()
}

func NextInt() int{
	ret, _ := strconv.Atoi(Next())
	return ret
}

package main

import "fmt"

func main() {
    var n,id int
    call := make(map[int]int)
    fmt.Scan(&n)
    ans, cnt := true, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&id)
        call[id]++
        if call[id] == 2 {
            cnt++
        } else if call[id] > 2 {
            ans = false
        }
    }
    if ans { fmt.Println(cnt) } else { fmt.Println(-1) }
}

package main

import "fmt"

func main() {
	var n, temp int
	fmt.Scan(&n)
	m := make(map[int]int)
	var out int
	for ; n > 0; n-- {
		fmt.Scan(&temp)
		m[temp]++
		if m[temp] > 2 {
			out = -1
		}
	}
	if out == -1 {
		fmt.Println(-1)
	} else {
		for _, v := range m {
			if v == 2 {
				out++
			}
		}
		fmt.Println(out)
	}
}

package main

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

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

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

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var s int
		fmt.Fscanf(r, "%d", &s)
		mp[s]++
	}

	count := 0
	for _, v := range mp {
		if v > 2 {
			fmt.Println("-1")
			return
		} else if v == 2 {
			count++
		}
	}

	fmt.Println(count)
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

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

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    m := make(map[int]int)
    for i := 0; i < n; i++ {
        x := nextInt()
        m[x]++
        if x != 0 && m[x] > 2 {
            fmt.Fprintln(out, -1)
            return
        }
    }
    ans := 0
    for k := range m {
        if m[k] == 2 {
            ans++
        }
    }

    fmt.Fprintln(out, ans)

}


It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road).Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside?

The first line contains two integers n and m (4 ≤ n ≤ 100, 1 ≤ m ≤ 100). Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.

If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print m characters. i-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.

package main

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

type Pair struct {
	a, b int
}

var visit []bool
var color []bool
var conflict [][]bool

var n, m int

func dfs(road int, c bool) bool {
	if visit[road] {
		return color[road] == c
	} else {
		visit[road], color[road] = true, c
		for i := 0; i < m; i++ {
			if conflict[road][i] {
				if !dfs(i, !c) {
					visit[road] = false
					return false
				}
			}
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	pairs := make([]Pair, m)

	color = make([]bool, m)
	visit = make([]bool, m)
	conflict = make([][]bool, m)

	for i := 0; i < m; i++ {
		conflict[i] = make([]bool, m)
		fmt.Fscanf(reader, "%d %d\n", &pairs[i].a, &pairs[i].b)
		if pairs[i].a > pairs[i].b {
			pairs[i].a, pairs[i].b = pairs[i].b, pairs[i].a
		}
	}
	for i := 0; i < m; i++ {
		for j := 0; j < m; j++ {
			conflict[i][j] = (pairs[i].a < pairs[j].a && pairs[j].a < pairs[i].b && pairs[i].b < pairs[j].b) ||
				(pairs[j].a < pairs[i].a && pairs[i].a < pairs[j].b && pairs[j].b < pairs[i].b)
		}
	}

	for i := 0; i < m; i++ {
		if !visit[i] {
			if !dfs(i, true) {
				fmt.Printf("Impossible")
				return
			}
		}
	}
	for i := 0; i < m; i++ {
		if color[i] {
			fmt.Printf("o")
		} else {
			fmt.Printf("i")
		}
	}
}

package main

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

type Pair struct {
	a, b int
}

var visit []bool
var color []bool
var conflict [][]bool

func dfs(m int, c bool) bool {
	if visit[m] {
		return color[m] == c
	} else {
		visit[m], color[m] = true, c
		for i := 0; i < m; i++ {
			if conflict[m][i] {
				if !dfs(i, !c) {
					visit[m] = false
					return false
				}
			}
		}
	}
	return true
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	pairs := make([]Pair, m)

	color = make([]bool, m)
	visit = make([]bool, m)
	conflict = make([][]bool, m)

	for i := 0; i < m; i++ {
		conflict[i] = make([]bool, m)
		fmt.Fscanf(reader, "%d %d\n", &pairs[i].a, &pairs[i].b)
		if pairs[i].a > pairs[i].b {
			pairs[i].a, pairs[i].b = pairs[i].b, pairs[i].a
		}
	}
	for i := 0; i < m; i++ {
		for j := 0; j < m; j++ {
			conflict[i][j] = (pairs[i].a < pairs[j].a && pairs[j].a < pairs[i].b && pairs[i].b < pairs[j].b) ||
				(pairs[j].a < pairs[i].a && pairs[i].a < pairs[j].b && pairs[j].b < pairs[i].b)
		}
	}
	if dfs(0, true) {
		for i := 0; i < m; i++ {
			if color[i] {
				fmt.Printf("o")
			} else {
				fmt.Printf("i")
			}
		}
	} else {
		fmt.Printf("Impossible")
	}
}


Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.Suppose you are given a positive integer $$$a$$$. You want to choose some integer $$$b$$$ from $$$1$$$ to $$$a - 1$$$ inclusive in such a way that the greatest common divisor (GCD) of integers $$$a \oplus b$$$ and $$$a \> \& \> b$$$ is as large as possible. In other words, you'd like to compute the following function:$$$$$$f(a) = \max_{0 < b < a}{gcd(a \oplus b, a \> \& \> b)}.$$$$$$Here $$$\oplus$$$ denotes the bitwise XOR operation, and $$$\&$$$ denotes the bitwise AND operation.The greatest common divisor of two integers $$$x$$$ and $$$y$$$ is the largest integer $$$g$$$ such that both $$$x$$$ and $$$y$$$ are divided by $$$g$$$ without remainder.You are given $$$q$$$ integers $$$a_1, a_2, \ldots, a_q$$$. For each of these integers compute the largest possible value of the greatest common divisor (when $$$b$$$ is chosen optimally).

The first line contains an integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of integers you need to compute the answer for. After that $$$q$$$ integers are given, one per line: $$$a_1, a_2, \ldots, a_q$$$ ($$$2 \le a_i \le 2^{25} - 1$$$) — the integers you need to compute the answer for.

For each integer, print the answer in the same order as the integers are given in input.

NoteFor the first integer the optimal choice is $$$b = 1$$$, then $$$a \oplus b = 3$$$, $$$a \> \& \> b = 0$$$, and the greatest common divisor of $$$3$$$ and $$$0$$$ is $$$3$$$.For the second integer one optimal choice is $$$b = 2$$$, then $$$a \oplus b = 1$$$, $$$a \> \& \> b = 2$$$, and the greatest common divisor of $$$1$$$ and $$$2$$$ is $$$1$$$.For the third integer the optimal choice is $$$b = 2$$$, then $$$a \oplus b = 7$$$, $$$a \> \& \> b = 0$$$, and the greatest common divisor of $$$7$$$ and $$$0$$$ is $$$7$$$.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscan(reader, &k)
	for i := 0; i < k; i++ {
		var request int64
		fmt.Fscan(reader, &request)
		var j uint
		for j = 25; j >= 0; j-- {
			var power int64 = 1 << j
			if request == power-1 {
				fmt.Println(largestDiv(request))
				break
			}
			if request >= (1 << j) {
				fmt.Println(1<<(j+1) - 1)
				break
			}
		}
	}
}

func largestDiv(request int64) int64 {
	var i float64
	for i = 3; i <= math.Sqrt(float64(request)); i += 2 {
		if request%int64(i) == 0 {
			return request / int64(i)
		}
	}
	return 1
}

/*
URL:
https://codeforces.com/problemset/problem/1110/C
*/

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
	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 (
	q int
	a int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		a = ReadInt()

		solve()
	}
}

func solve() {
	ub := 0
	for i := 0; i < 30; i++ {
		if NthBit(a, i) == 1 {
			ub = i
		}
	}

	if ub+1 != PopCount(a) {
		ans := 1<<uint(ub+1) - 1
		fmt.Println(ans)
		return
	}

	memo := TrialDivision(a)
	mini := 1 << 30
	for k := range memo {
		ChMin(&mini, k)
	}

	ans := 1
	for k, v := range memo {
		if k == mini {
			ans *= PowInt(k, v-1)
			continue
		}
		ans *= PowInt(k, v)
	}
	fmt.Println(ans)
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int) map[int]int {
	var i, exp int
	p := map[int]int{}

	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	for i = 2; i*i <= n; i++ {
		exp = 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

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

/*********** 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"
	"os"
)

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

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

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

func main() {
	defer writer.Flush()

	// for ii := 2; ii < 27; ii++ {

	// 	i := 1 << uint(ii)
	// 	i--

	// 	mx := 0
	// 	for j := 1; j < i; j++ {
	// 		t1 := gcd(i^j, i&j)
	// 		if t1 > mx {
	// 			mx = t1
	// 		}
	// 	}
	// 	fmt.Print(mx, ",")

	// }

	hsmp := make(map[int]int)

	arr := []int{1, 1, 5, 1, 21, 1, 85, 73, 341, 89, 1365, 1, 5461, 4681, 21845, 1, 87381, 1, 349525, 299593, 1398101, 178481, 5592405, 1082401, 22369621}

	for i := 0; i < 25; i++ {
		t1 := 1 << uint(i+2)
		t1--
		hsmp[t1] = arr[i]
	}

	// fmt.Println(hsmp)

	var q, t1 int

	scanf("%d\n", &q)

	for i := 0; i < q; i++ {
		scanf("%d\n", &t1)
		val, ok := hsmp[t1]
		if ok {
			printf("%d\n", val)
			continue
		}
		hsbit := 0
		for t1 > 0 {
			hsbit++
			t1 /= 2
		}
		printf("%d\n", 1<<uint(hsbit)-1)
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"math/bits"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

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

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func gcd(a, b int) int {
	for ; b > 0; a, b = b, a%b {
	}
	return a
}

func solve(a int) int {
	var res int
	for i := 1; i < a; i++ {
		g := gcd(i^a, i&a)
		if g > res {
			res = g
		}
	}
	return res
}

func main() {
	defer writer.Flush()

	q := NextInt()

l:
	for ; q > 0; q-- {
		x := uint(NextInt())

		if x&(x+1) == 0 {
			for t := uint(2); t*t <= x; t++ {
				if x%t == 0 {
					println(x / t)
					continue l
				}
			}
			println(1)
			continue l
		}

		l := bits.Len(x)
		println((1 << uint(l)) - 1)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscan(reader, &k)
	for i := 0; i < k; i++ {
		var request int64
		fmt.Fscan(reader, &request)
		var j uint
		for j = 25; j >= 0; j-- {
			var power int64 = 1 << j
			if request == power-1 {
				fmt.Println(largestDiv(request))
				break
			}
			if request >= (1 << j) {
				fmt.Println(1<<(j+1) - 1)
				break
			}
		}
	}
}

func largestDiv(request int64) int64 {
	var i float64
	for i = 3; i <= math.Sqrt(float64(request)); i += 2 {
		if request%int64(i) == 0 {
			fmt.Println(request / int64(i))
		}
	}
	return 1
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscan(reader, &k)
	for i := 0; i < k; i++ {
		var request int64
		fmt.Fscan(reader, &request)
		var j uint
		for j = 25; j >= 0; j-- {
			var power int64 = 1 << j
			if request == power-1 {
				found := false
				var k int64
				for k = 1; k < request/2; k++ {
					if request%(k*2+1) == 0 {
						fmt.Println(k)
						found = true
						break
					}
				}
				if !found {
					fmt.Println(i)
				}
				break
			}
			if request >= (1 << j) {
				fmt.Println(1<<(j+1) - 1)
				break
			}
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1110/C
*/

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
	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 (
	q int
	a int
)

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		a = ReadInt()

		solve()
	}
}

func solve() {
	ub := 0
	for i := 0; i < 30; i++ {
		if NthBit(a, i) == 1 {
			ub = i
		}
	}

	if ub+1 != PopCount(a) {
		ans := 1<<uint(ub+1) - 1
		fmt.Println(ans)
		return
	}

	memo := TrialDivision(a)
	mini := 1 << 30
	for k := range memo {
		ChMin(&mini, k)
	}

	ans := 1
	for k, v := range memo {
		if k == mini {
			continue
		}
		ans *= PowInt(k, v)
	}
	fmt.Println(ans)
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// TrialDivision returns the result of prime factorization of integer N.
func TrialDivision(n int) map[int]int {
	var i, exp int
	p := map[int]int{}

	if n <= 1 {
		panic(errors.New("[argument error]: TrialDivision only accepts a NATURAL number"))
	}

	for i = 2; i*i <= n; i++ {
		exp = 0
		for n%i == 0 {
			exp++
			n /= i
		}

		if exp == 0 {
			continue
		}
		p[i] = exp
	}
	if n > 1 {
		p[n] = 1
	}

	return p
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

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

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