Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally,   You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions).  Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.    The picture shows a square that contains red and green rectangles.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$.

NoteBelow are the answers for the first two test cases:

package main

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

func main() {
	var t, a, b int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b)
		min, max := minmax(a, b)
		_, max = minmax(min*2, max)
		fmt.Println(max * max)
	}
}

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

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		a, b := readTwoNums(reader)

		fmt.Println(solve(a, b))
	}
}

func solve(a, b int) int {
	if a > b {
		a, b = b, a
	}
	x := max(2*a, b)

	return x * x
}

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

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		a, b := s.NextInt(), s.NextInt()
		res := 0
		x := max(a, 2*b)
		res = x * x

		y := max(b, 2*a)
		if res > y*y {
			res = y * y
		}

		fmt.Println(res)
	}
}

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

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

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

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	r1 := min(max(a+b, b), max(a+b, a))
	r2 := min(max(2*a, b), max(2*b, a))
	fmt.Println(min(r1, r2)*min(r1, r2))
}

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

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

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	c := min(max(2*a, b), max(2*b, a))
	fmt.Println(c*c)
}

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

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

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

// Max returns the larger of x or y.
func Max(x, y int) int {
    if x < y {
        return y
    }
    return x
}

// Min returns the smaller of x or y.
func Min(x, y int) int {
    if x > y {
        return y
    }
    return x
}

func main() {
	var t,a,b,ans int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a)
		fmt.Scan(&b)
		if a>b {
			var temp int
			temp = b
			b = a
			a = temp
		}
		ans = Max(a+a,b);
		fmt.Println(ans * ans)
	}

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Text()
	for scanner.Scan() {
		text := scanner.Text()
		num := strings.Split(text, " ")
		a, _ := strconv.Atoi(num[0])
		b, _ := strconv.Atoi(num[1])
		if a < b {
			a *= 2
		} else {
			b *= 2
		}
		if a > b {
			b = a
		} else {
			a = b
		}

		fmt.Println(a * b)
	}
}

package main

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

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

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

func sol(a,b int64) int64 {
	if(a==1 && b==1){
		return 4
	}else if(a==1){
		return b*b
	}else if(b==1){
		return a*a
	}else{
		x,y:=MnMx(a,b)
		if(y<=2*x){
		return 2*x*2*x
		}else{
			return y*y
		}
	}

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main
import(
	"fmt"
	"math"
)
func main()  {
	var test,a,b int
	fmt.Scan(&test)
	for i:=0;i<test;i++{
		fmt.Scan(&a)
		fmt.Scan(&b)
		c:=math.Min(float64(a),float64(b))
		d:=math.Max(float64(a),float64(b))
		if c*2>=d{
			fmt.Println(math.Pow(c*2,2))
		}else{
			fmt.Println(math.Pow(d,2))
		}

	}
}

/*
URL:
https://codeforces.com/contest/1360/problem/0
*/

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 (
	t    int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt2()
		solve(a, b)
	}
}

func solve(a, b int) {
	i := Max(2*a, b)
	j := Max(a, 2*b)
	k := Max(a, b, a+b)

	l := Min(i, j, k)
	fmt.Println(l * l)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
  "fmt"
)

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

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

func main() {
  var t int
  fmt.Scan(&t)
  for i := 0 ; i < t; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    x := min(a, b)
    y := max(a, b)
    if x * 2 < y {
      fmt.Println(y * y)
    } else {
      fmt.Println(4 * x * x)
    }
  }
}

package main

import "fmt"

func main() {
	var t int
	var a int
	var b int
	var side int

	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		if a > b {
			if b*2 > a {
				side = b * 2
			} else {
				side = a
			}
		}
		if a < b {
			if a*2 > b {
				side = a * 2
			} else {
				side = b
			}
		}
		if a == b {
			side = a * 2
		}
		fmt.Println(side*side)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scanln(&n)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		var a int
		var b int
		_, err := fmt.Scanf("%d %d\n", &a, &b)
		if err != nil {
			panic("Invalid input")
		}

		min := Min(a, b)
		max := Max(a, b)
		resA := Max(max, min*2)
		fmt.Println(resA * resA)
	}
}

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

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

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		a := readInt()
		b := readInt()
		if b < a {
			a, b = b, a
		}
		var res int
		if 2 * a < b {
			res = b * b
		} else {
			res = (2 * a) * (2 * a)
		}
		fmt.Println(res)
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

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

	var t, a,b int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a,&b)
		if a > b {
			a, b = b, a
		}
		if 2*a<=b{
			Fprintln(out, b*b)
		} else {
			Fprintln(out, 4*a*a)
		}
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		a, b := ScanInt(), ScanInt()
		ar1 := Mx((2*a), b) * Mx((2*a), b)
		ar2 := Mx(a, 2 * b) * Mx(a, 2 * b)
		P(Mn(ar1, ar2))
	}

}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main()  {
	var test,a,b int
	fmt.Scan(&test)
	for i:=0;i<test;i++{
		fmt.Scan(&a,&b)
		c:=[]int{a,b}
		sort.Ints(c)
		fmt.Println(math.Pow(math.Max(float64(c[0]*2),float64(c[1])),2))
	}
}

package main

import (
	"fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,m int
		fmt.Scan(&n)
		fmt.Scan(&m)
		if  n>m {
		var t = n
		  n = m
		  m = t
		}
		if 2*n>m{
			var t = 2*n
		  n = m
		  m = t
		}
		fmt.Println(m*m)
	}
}

package main
import "fmt"
func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
func main(){
    var t, a, b int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&a, &b)
        if a > b {
            a, b = b, a
        }
        if (a+a)*b > (a+b)*b {
            fmt.Println(max(a+b, b) * max(a+b, b))
        } else {
            fmt.Println(max(a+a, b) * max(a+a, b))
        }
    }
}

package main
import (
    "fmt"
    "os"
    "bufio"
)
func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
func main(){
    var t, a, b int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &a, &b)
        if a > b {
            a, b = b, a
        }
        if (a+a)*b > (a+b)*b {
            fmt.Println(max(a+b, b) * max(a+b, b))
        } else {
            fmt.Println(max(a+a, b) * max(a+a, b))
        }
    }
}

package main

import (
	"fmt"
)

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

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

func square(a int) int {
    return a * a
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		fmt.Println(min(square(max(2 * a, b)), square(max(2 * b, a))))
	}
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for tt := rd(); tt > 0; tt-- {
		a, b := rd(), rd()
		if a > b {
			a, b = b, a
		}
		ans := max(2*a, b)
		Fprintln(out, ans*ans)
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
    "fmt"
    "math"
)

func Min(a, b, c float64) float64 {
    return math.Min(a, math.Min(b, c))
}

func main() {
  var t int
  var a, b float64

  fmt.Scan(&t)
  for ;t > 0; t-- {
      fmt.Scan(&a, &b)
      ans := Min(math.Max(2 * a, b), math.Max(a, 2 * b), a + b)
      fmt.Println(math.Pow(ans, 2))
  }
}

package main

import (
	"fmt"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var a, b, tmp int
		fmt.Scan(&a, &b)
		if a > b {
			tmp = a
			a = b
			b = tmp
		}
		s := 2*a
		if s < b {
			s = b
		}
		fmt.Println(s*s)
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanln(in, &t)
	for i := 0; i < t; i++ {
		a, b := 0, 0
		fmt.Fscanln(in, &a, &b)
		if a < b {
			a, b = b, a
		}
		ans := 2 * b
		if ans < a {
			ans = a
		}
		ans *= ans
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

// https://codeforces.com/problemset/problem/1360/A
// A. Minimal Square
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Find the minimum area of a square land on which you can place two identical rectangular a×b

// houses. The sides of the houses should be parallel to the sides of the desired square land.

// Formally,

//     You are given two identical rectangles with side lengths a

// and b (1≤a,b≤100

//     ) — positive integers (you are given just the sizes, but not their positions).
//     Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.

// Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.
// The picture shows a square that contains red and green rectangles.
// Input

// The first line contains an integer t
// (1≤t≤10000) —the number of test cases in the input. Then t

// test cases follow.

// Each test case is a line containing two integers a
// , b (1≤a,b≤100

// ) — side lengths of the rectangles.
// Output

// Print t
// answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions a×b.

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

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var a, b int

		_, _ = fmt.Fscan(bufStdin, &a, &b)

		shorterSide, longerSide := intMin(a, b), intMax(a, b)

		squareSide := intMax(2*shorterSide, longerSide)
		area := squareSide * squareSide
		_, _ = fmt.Fprintln(bufStdout, area)
	}
}

func intMin(v1, v2 int) int {
	if v1 < v2 {
		return v1
	}
	return v2
}
func intMax(v1, v2 int) int {
	if v1 > v2 {
		return v1
	}
	return v2
}

package main

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

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		a, b = minmax(a, b)
		if 2*a > b {
			fmt.Fprintln(w, 4*a*a)
		} else {
			fmt.Fprintln(w, b*b)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

type numpair struct {
	a int
	b int
}

// https://codeforces.com/problemset/problem/1360/A
// комментарий к решению
func taskSolution(in []numpair) string {
	ans := make([]int, len(in))
	for i := 0; i < len(in); i += 1 {
		a, b := in[i].a, in[i].b
		if a > b {
			a, b = b, a
		}
		if 2*a > b {
			ans[i] = 4 * a * a
		} else {
			ans[i] = b * b
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	in := []numpair{}
	for i := 0; i < t; i += 1 {
		var a, b int
		if _, err := fmt.Scan(&a, &b); err != nil {
			panic(err)
		}
		in = append(in, numpair{a: a, b: b})
	}

	fmt.Println(taskSolution(in))
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

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

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

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

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

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

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

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

func sol(a, b int64) int64 {
	side := max(min(a,b)*2, max(a,b))
	return side * side
}

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i/2 >= a*b && i/2 >= min(a, b)  {
			fmt.Println(i*i)
			return
		}
	}
}

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

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i/2 >= a*b && i/2 >= min(a, b)  {
			fmt.Println(int64(i)*int64(i))
			return
		}
	}
}

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

// https://codeforces.com/contest/1355/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i >= 2*a*b && i >= 2*min(a, b)  {
			fmt.Println(i*i)
			return
		}
	}
}

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

package main

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

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

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

func sol(a,b int64) int64 {
	if(a==1 && b==1){
		return 4
	}else if(a==1){
		return b*b
	}else if(b==1){
		return a*a
	}else{
		x,_:=MnMx(a,b)
		return 2*x*2*x
	}

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
  "fmt"
)

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

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

func main() {
  var t int
  fmt.Scanf("%d", &t)
  for i := 0 ; i < t; i++ {
    var a, b int
    fmt.Scanf("%d%d", &a, &b)
    x := min(a, b)
    y := max(a, b)
    if x * 2 < y {
      fmt.Println(y * y)
    } else {
      fmt.Println(4 * x * x)
    }
  }
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		a := readInt()
		b := readInt()
		if b < a {
			a, b = b, a
		}
		var res int
		if a * a < b {
			res = b * b
		} else {
			res = (2 * a) * (2 * a)
		}
		fmt.Println(res)
	}
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}


On a circle lie $$$2n$$$ distinct points, with the following property: however you choose $$$3$$$ chords that connect $$$3$$$ disjoint pairs of points, no point strictly inside the circle belongs to all $$$3$$$ chords. The points are numbered $$$1, \, 2, \, \dots, \, 2n$$$ in clockwise order.Initially, $$$k$$$ chords connect $$$k$$$ pairs of points, in such a way that all the $$$2k$$$ endpoints of these chords are distinct.You want to draw $$$n - k$$$ additional chords that connect the remaining $$$2(n - k)$$$ points (each point must be an endpoint of exactly one chord).In the end, let $$$x$$$ be the total number of intersections among all $$$n$$$ chords. Compute the maximum value that $$$x$$$ can attain if you choose the $$$n - k$$$ chords optimally.Note that the exact position of the $$$2n$$$ points is not relevant, as long as the property stated in the first paragraph holds.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le k \le n$$$) — half the number of points and the number of chords initially drawn. Then $$$k$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, \, y_i \le 2n$$$, $$$x_i \ne y_i$$$) — the endpoints of the $$$i$$$-th chord. It is guaranteed that the $$$2k$$$ numbers $$$x_1, \, y_1, \, x_2, \, y_2, \, \dots, \, x_k, \, y_k$$$ are all distinct.

For each test case, output the maximum number of intersections that can be obtained by drawing $$$n - k$$$ additional chords.

NoteIn the first test case, there are three ways to draw the $$$2$$$ additional chords, shown below (black chords are the ones initially drawn, while red chords are the new ones):  We see that the third way gives the maximum number of intersections, namely $$$4$$$.In the second test case, there are no more chords to draw. Of course, with only one chord present there are no intersections.In the third test case, we can make at most one intersection by drawing chords $$$1-3$$$ and $$$2-4$$$, as shown below:

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-- {
		n := _int()
		k := _int()
		xy := make([][2]int, k)
		for i := range xy {
			xy[i][0] = _int() - 1
			xy[i][1] = _int() - 1
		}
		printf("%d\n", sol(n, k, xy))
	}
}

func sol(n, k int, xy [][2]int) int {
	points := make([]int, 2*n)
	for i := range points {
		points[i] = -1
	}
	for i := range xy {
		points[xy[i][0]] = xy[i][1]
		points[xy[i][1]] = xy[i][0]
	}
	// printf("%v\n", points)
	p1 := 0 // p1: first untaken position
	for p1 < len(points) && points[p1] != -1 {
		p1++
	}
	if p1 != len(points) {
		p2 := p1 + 1 // p2: opposite position
		off := 0
		target := n - k // (2n - 2k)/2
		for {
			if points[p2] == -1 {
				off++
				if off == target {
					break
				}
			}
			p2++
			if p2 == len(points) {
				p2 = 0
			}
		}
		for {
			points[p1] = p2
			points[p2] = p1
			refp1 := p1
			for points[p1] != -1 {
				p1++
				if p1 == len(points) {
					p1 = 0
				}
				if p1 == refp1 {
					break // this is very ugly
				}
			}
			if p1 == refp1 {
				break // this is very ugly
			}
			for points[p2] != -1 {
				p2++
				if p2 == len(points) {
					p2 = 0
				}
			}
		}
		// printf("%v\n", points)
	}
	ret := 0
	chords := [][2]int{}
	for i := range points {
		if points[i] == -1 {
			continue // avoid double counting
		}
		from, to := i, points[i]
		if points[points[i]] != i {
			panic("from != to")
		}
		points[points[i]] = -1
		points[i] = -1
		curr := [2]int{from, to}
		for _, isect := range chords {
			if intersect(isect, curr) {
				ret++
			}
		}
		chords = append(chords, curr)
    // printf("%v\n", chords)
	}
	return ret
}

func intersect(a, b [2]int) bool {
	if a[0] > a[1] {
		a[0], a[1] = a[1], a[0]
	}
	if b[0] > b[1] {
		b[0], b[1] = b[1], b[0]
	}
	if between(a[0], b[0], a[1]) && !between(a[0], b[1], a[1]) {
		return true
	}
	if between(a[0], b[1], a[1]) && !between(a[0], b[0], a[1]) {
		return true
	}
	if between(b[0], a[0], b[1]) && !between(b[0], a[1], b[1]) {
		return true
	}
	if between(b[0], a[1], b[0]) && !between(b[0], a[0], b[1]) {
		return true
	}
	return false
}

func between(a, b, c int) bool {
	return a < b && b < c
}

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) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

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 move(pos int, used []bool, steps int) int {
	for i := 0; i < steps; i += 1 {
		for used[pos] {
			pos = (pos + 1) % len(used)
		}
		if i+1 < steps {
			pos = (pos + 1) % len(used)
		}
	}
	return pos
}

func ordered(c []int) (int, int) {
	if c[0] < c[1] {
		return c[0], c[1]
	}
	return c[1], c[0]
}

func intersect(ca, cb []int) bool {
	la, ra := ordered(ca)
	lb, rb := ordered(cb)
	return (la <= lb && lb <= ra && ra <= rb) ||
		(lb <= la && la <= rb && rb <= ra)
}

func countPairs(cs [][]int) int {
	res := 0
	for i := 0; i < len(cs); i += 1 {
		for j := i + 1; j < len(cs); j += 1 {
			if intersect(cs[i], cs[j]) {
				res += 1
			}
		}
	}
	return res
}

func solve(cs [][]int, n int) int {
	if len(cs) < n {
		used := make([]bool, 2*n)
		for _, c := range cs {
			used[c[0]] = true
			used[c[1]] = true
		}

		k := len(cs)
		l := move(0, used, 2*(n-k)+1)
		r := move(0, used, n-k+1)

		for i := 0; i < n-k; i += 1 {
			cs = append(cs, []int{l, r})
			used[l] = true
			used[r] = true
			if i+1 < n-k {
				l = move(l, used, 1)
				r = move(r, used, 1)
			}
		}
	}
	return countPairs(cs)
}

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

	for i := 0; i < tests; i += 1 {
		n, k := stdin.Int(), stdin.Int()
		c := make([][]int, k)
		for j := range c {
			c[j] = []int{stdin.Int() - 1, stdin.Int() - 1}
		}
		fmt.Println(solve(c, n))
	}
}


At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.The nameplate is to be rectangular and the text on it will be printed as a table of several rows and columns. Having some measurements done, the organizers have found out that the number $$$a$$$ of rows cannot be greater than $$$5$$$ while the number $$$b$$$ of columns cannot exceed $$$20$$$. Every cell of the table will contain either an asterisk («*») or a letter of user's handle.Furthermore, the organizers want the rows of the table to be uniform, which means that the number of asterisks used in different rows should differ by at most one (i.e. you can't have two asterisks in the first row and none in the second). The main goal, however, is to obtain the winner's handle precisely when reading the table from top to bottom and from left to right in every row (skipping asterisks).The organizers want for the nameplate to have as few rows as possible and among all valid tables with the minimum number of rows they want to choose the one that has the minimum number of columns.The winner is not yet determined so your task is to write a program that, given a certain handle, generates the necessary table.

The only line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), comprised of uppercase and lowercase Latin letters,  — the handle of the winner.

In the first line output the minimum number $$$a$$$ of rows in the table and the minimum number $$$b$$$ of columns in an optimal table with rows. The following $$$a$$$ lines should contain $$$b$$$ characters each  — any valid table.

3 15
MyNameIsLifeIAm
ForeverByYourSi
deMyNameIsL*ife

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 fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if j >= 1 {
		j = 0
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}
	if j >= 0 {
		j = 0
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j-1, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j+1, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

import "fmt"

func main() {

	var s string
	fmt.Scan(&s)

	length := len(s)
	lines := 1
	devider := -1
	var extras int
	for ; lines <= 5; lines++ {
		for d := 1; d <= 20; d++ {
			extras = lines * d - length
			if extras >= 0 && extras < lines {
				devider = d
				break
			}
		}
		if devider != -1 {
			break
		}
	}

	fmt.Printf("%d %d\n", lines, devider)

	counter := 0
	minus := 0
	for i := 0; i < lines; i++ {
		if extras > 0 {
			fmt.Printf("*")
			extras--
			minus = 1
		} else {
			minus = 0
		}
		for j := 0; j < devider-minus; j++ {
			fmt.Printf("%c", s[counter])
			counter++
		}
		fmt.Println()
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	fmt.Scan(&s)
	a := len(s) / 20
	if len(s)%20 > 0 {
		a++
	}

	b, e := len(s)/a, len(s)%a
	if e > 0 {
		b++
	}
	fmt.Println(a, b)
	l := 0
	for i := 0; i < a; i++ {
		w := b
		if (e > 0) && (i >= e) {
			w--
			fmt.Print("*")
		}
		fmt.Println(s[l : l+w])
		l = l + w
	}
}

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 fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j-1, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j+1, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

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 fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

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 fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

import "fmt"

func main() {

	var s string
	fmt.Scan(&s)

	length := len(s)
	lines := 1
	devider := -1
	var extras int
	for ; lines <= 5; lines++ {
		for d := 2; d <= 20; d++ {
			extras = lines * d - length
			if extras >= 0 && extras < lines {
				devider = d
				break
			}
		}
		if devider != -1 {
			break
		}
	}

	fmt.Printf("%d %d\n", lines, devider)

	counter := 0
	minus := 0
	for i := 0; i < lines; i++ {
		if extras > 0 {
			fmt.Printf("*")
			extras--
			minus = 1
		} else {
			minus = 0
		}
		for j := 0; j < devider-minus; j++ {
			fmt.Printf("%c", s[counter])
			counter++
		}
		fmt.Println()
	}
}


Polycarp is an organizer of a Berland ICPC regional event. There are $$$n$$$ universities in Berland numbered from $$$1$$$ to $$$n$$$. Polycarp knows all competitive programmers in the region. There are $$$n$$$ students: the $$$i$$$-th student is enrolled at a university $$$u_i$$$ and has a programming skill $$$s_i$$$.Polycarp has to decide on the rules now. In particular, the number of members in the team.Polycarp knows that if he chooses the size of the team to be some integer $$$k$$$, each university will send their $$$k$$$ strongest (with the highest programming skill $$$s$$$) students in the first team, the next $$$k$$$ strongest students in the second team and so on. If there are fewer than $$$k$$$ students left, then the team can't be formed. Note that there might be universities that send zero teams.The strength of the region is the total skill of the members of all present teams. If there are no teams present, then the strength is $$$0$$$.Help Polycarp to find the strength of the region for each choice of $$$k$$$ from $$$1$$$ to $$$n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of universities and the number of students. The second line of each testcase contains $$$n$$$ integers $$$u_1, u_2, \dots, u_n$$$ ($$$1 \le u_i \le n$$$) — the university the $$$i$$$-th student is enrolled at. The third line of each testcase contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the programming skill of the $$$i$$$-th student. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase print $$$n$$$ integers: the strength of the region — the total skill of the members of the present teams — for each choice of team size $$$k$$$.

package main

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

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

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		sToDList[n] = nil
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sz := len(v)
			if sz == 0 {
				continue
			}
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < sz; j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= sz; j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		uni := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &uni[i])
			uni[i]--
		}
		stu := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &stu[i])
		}

		rec := make([][]int64, n)
		for i := 0; i < n; i++ {
			rec[uni[i]] = append(rec[uni[i]], int64(stu[i]))
		}

		ans := make([]int64, n + 1)
		for i := 0; i < n; i++ {
			sort.Slice(rec[i], func(ii, jj int) bool {
				return rec[i][ii] > rec[i][jj]
			})

			m := len(rec[i])
			for j := 1; j < m; j++ {
				rec[i][j] += rec[i][j - 1]
			}

			for j := 1; j <= m; j++ {
				ans[j] += rec[i][m / j * j - 1]
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Fprint(out, ans[i], " ")
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		//tot := int64(0)
		u := make([]int, n)
		for i := range u {
			Fscan(in, &u[i])
		}
		a := make([][]int, n)
		for _, v := range u {
			v--
			var w int
			Fscan(in, &w)
			a[v] = append(a[v], w)
		}

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

		sum := make([][]int64, n)
		for kk := range a {
			sort.Ints(a[kk])
			sum[kk] = make([]int64, len(a[kk])+1)
			for i, v := range a[kk] {
				sum[kk][i+1] = sum[kk][i] + int64(v)
			}
			//tot += sum[kk][len(a[kk])]
		}

		for k := 1; k <= n; k++ {
			ans := int64(0)
			for i, a := range a {
				if len(a) < k {
					break
				}

				j :=  len(a)%k
				ans += sum[i][len(a)] - sum[i][j]
			}
			Fprint(out, ans, " ")
		}
		Fprintln(out)
	}

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

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

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

package main

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

const N = 200000

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		// read data
		fmt.Fscan(in, &n)
		str := make([]int64, n+1)
		participantUni := make([]int, n)
		uniSize := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &participantUni[i])
			participantUni[i]--
			uniSize[participantUni[i]]++
		}
		uni := make([][]int, n)
		for i := range uni {
			uni[i] = make([]int, 0, uniSize[i])
		}
		var participantStr int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &participantStr)
			uni[participantUni[i]] = append(uni[participantUni[i]], participantStr)
			str[1] += int64(participantStr)
		}

		// prepare data
		sort.Slice(uni, func(i, j int) bool {
			return len(uni[i]) > len(uni[j])
		})
		a := make([][]int64, len(uni[0])+1)
		var l int
		for i := 0; i < len(uni) && len(uni[i]) > 1; i++ {
			l = len(uni[i])
			if a[l] == nil {
				a[l] = make([]int64, l)
			}
			sort.Sort(sort.Reverse(sort.IntSlice(uni[i])))
			for j := 0; j < l; j++ {
				a[l][j] += int64(uni[i][j])
			}
		}
		for i := 2; i < len(a); i++ {
			for j := 1; j < len(a[i]); j++ {
				a[i][j] += a[i][j-1]
			}
		}

		// solve
		for i := 2; i < len(a); i++ {
			if a[i] == nil {
				continue
			}
			for j := 2; j <= i; j++ {
				str[j] += a[i][len(a[i])-1-len(a[i])%j]
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Fprint(out, str[i], " ")
		}
		fmt.Fprintln(out)
		out.Flush()
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

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

		u := make([]int, 0, n)
		s := make([]int, 0, n)

		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			u = append(u, temp)
		}

		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			s = append(s, temp)
		}

		mp := make(map[int][]int64)

		for i := 0; i < n; i++ {
			uni := u[i]
			scr := int64(s[i])

			if _, ok := mp[uni]; !ok {
				mp[uni] = make([]int64, 0)
			}

			mp[uni] = append(mp[uni], scr)
		}

		for _, slc := range mp {
			sort.SliceStable(slc, func(i, j int) bool {
				return slc[i] < slc[j]
			})

			for i := 1; i < len(slc); i++ {
				slc[i] += slc[i-1]
			}
		}

		ans := make([]int64, n+1)
		for _, v := range mp {
			for g := 1; g <= len(v); g++ {
				left := len(v) % g

				ans[g] += v[len(v)-1]
				if left > 0 {
					ans[g] -= v[left-1]
				}
			}
		}

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		u := make([]int, n)
		p := make([][]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &u[i])
			u[i]--
		}
		for i := 0; i < n; i++ {
			var s int64
			fmt.Fscan(in, &s)
			p[u[i]] = append(p[u[i]], s)
		}
		ans := make([]int64, n+1)

		for i := 0; i < n; i++ {
			sort.Slice(p[i], func(u, v int) bool {
				return p[i][u] < p[i][v]
			})
			for j := 1; j < len(p[i]); j++ {
				p[i][j] += p[i][j-1]
			}
			for j := 1; j <= len(p[i]); j++ {
				if len(p[i])%j != 0 {
					ans[j] += p[i][len(p[i])-1] - p[i][len(p[i])%j-1]
				} else {
					ans[j] += p[i][len(p[i])-1]
				}
			}
		}
		for i := 1; i < n+1; i++ {
			fmt.Fprint(out, ans[i], " ")
		}
		fmt.Fprintln(out)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sz := len(v)
			if sz == 0 {
				continue
			}
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < sz; j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= sz; j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= len(v); j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		s, d := make([]int64, n), make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
		}
		sToDList := make(map[int64][]int64)
		for i, v := range s {
			sToDList[v] = append(sToDList[v], int64(d[i]))
		}
		for i, v := range sToDList {
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			sToDList[i] = prefix
		}

		for k := int64(1); k <= n; k++ {
			total := int64(0)
			for _, v := range sToDList {
				if k > int64(len(v) -1) {
					continue
				}
				mod := int64(len(v)) % k
				total += v[int64(len(v)-1)-mod]
			}
			fmt.Fprint(_w, total, " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		s, d := make([]int64, n), make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
		}
		sToDList := make(map[int64][]int64)
		for i, v := range s {
			sToDList[v] = append(sToDList[v], int64(d[i]))
		}
		for i, v := range sToDList {
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			sToDList[i] = prefix
		}

		for k := int64(1); k <= n; k++ {
			total := int64(0)
			for _, v := range sToDList {
				if k > int64(len(v)) {
					continue
				}
				mod := int64(len(v)) % k
				total += v[int64(len(v)-1)-mod]
			}
			fmt.Fprint(_w, total, " ")
		}
		fmt.Fprintln(_w)
	}

}


You are given a sequence $$$A$$$, where its elements are either in the form + x or -, where $$$x$$$ is an integer.For such a sequence $$$S$$$ where its elements are either in the form + x or -, define $$$f(S)$$$ as follows:  iterate through $$$S$$$'s elements from the first one to the last one, and maintain a multiset $$$T$$$ as you iterate through it.  for each element, if it's in the form + x, add $$$x$$$ to $$$T$$$; otherwise, erase the smallest element from $$$T$$$ (if $$$T$$$ is empty, do nothing).  after iterating through all $$$S$$$'s elements, compute the sum of all elements in $$$T$$$. $$$f(S)$$$ is defined as the sum. The sequence $$$b$$$ is a subsequence of the sequence $$$a$$$ if $$$b$$$ can be derived from $$$a$$$ by removing zero or more elements without changing the order of the remaining elements. For all $$$A$$$'s subsequences $$$B$$$, compute the sum of $$$f(B)$$$, modulo $$$998\,244\,353$$$.

The first line contains an integer $$$n$$$ ($$$1\leq n\leq 500$$$) — the length of $$$A$$$. Each of the next $$$n$$$ lines begins with an operator + or -. If the operator is +, then it's followed by an integer $$$x$$$ ($$$1\le x<998\,244\,353$$$). The $$$i$$$-th line of those $$$n$$$ lines describes the $$$i$$$-th element in $$$A$$$.

Print one integer, which is the answer to the problem, modulo $$$998\,244\,353$$$.

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func ReadSign() bool {
	in.Scan()
	if in.Bytes()[0] == '-' {
		return false
	}
	return true
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

const (
	N = 505
	M = 998244353
)

var (
	a [N]int
	f [N][N]int
)

func main() {
	defer out.Flush()
	n := Read()
	for i := 1; i <= n; i++ {
		if ReadSign() {
			a[i] = Read()
		}
	}
	s := 0
	for k := 1; k <= n; k++ {
		if a[k] == 0 {
			continue
		}
		for i := 0; i <= n; i++ {
			for j := 0; j <= n; j++ {
				f[i][j] = 0
			}
		}
		f[0][0] = 1
		for i := 1; i <= n; i++ {
			if a[i] == 0 {
				if i < k {
					f[i][0] = (f[i][0] + f[i-1][0]) % M
				}
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j+1]) % M
				}
			} else if a[i] < a[k] || a[i] == a[k] && i < k {
				for j := 1; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j-1]) % M
				}
			} else {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
			if i != k {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
		}
		for i := 0; i <= n; i++ {
			s = (s + int((int64(f[n][i])*int64(a[k]))%M)) % M
		}
	}
	Fprintln(out, s)
}

package main

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

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

	var buf bytes.Buffer

	tc := 1

	for tc > 0 {
		tc--
		n := readNum(reader)
		S := make([]string, n)
		for i := 0; i < n; i++ {
			S[i], _ = reader.ReadString('\n')
		}
		res := solve(n, S)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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
}

const MOD = 998244353

func solve(n int, S []string) int {
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		if S[i][0] == '+' {
			readInt([]byte(S[i]), 2, &a[i+1])
		}
	}

	var ans int64

	f := make([][]int64, n+2)
	for i := 0; i <= n+1; i++ {
		f[i] = make([]int64, n+2)
	}

	for t := 1; t <= n; t++ {
		if a[t] == 0 {
			continue
		}
		for i := 0; i <= n+1; i++ {
			for j := 0; j <= n+1; j++ {
				f[i][j] = 0
			}
		}
		f[0][0] = 1
		for i := 1; i <= n; i++ {
			for j := 0; j <= i; j++ {
				if a[i] == 0 {
					// a minus
					if i <= t || j > 0 {
						f[i][max(j-1, 0)] = modAdd(f[i][max(j-1, 0)], f[i-1][j])
					}
				} else {
					if a[i] < a[t] || (a[i] == a[t] && i < t) {
						f[i][j+1] = modAdd(f[i][j+1], f[i-1][j])
					} else {
						f[i][j] = modAdd(f[i][j], f[i-1][j])
					}
				}

				if i != t {
					f[i][j] = modAdd(f[i][j], f[i-1][j])
				}
			}
		}

		for i := 0; i <= n; i++ {
			ans = modAdd(ans, f[n][i]*int64(a[t])%MOD)
		}
	}

	return int(ans)
}

func modAdd(a, b int64) int64 {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1542D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353

	var n int
	var op string
	Fscan(in, &n)
	a := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		if Fscan(in, &op); op == "+" {
			Fscan(in, &a[i])
		}
	}

	ans := int64(0)
	for p := 1; p <= n; p++ {
		v := a[p]
		if v == 0 {
			continue
		}
		dp := make([][]int, n+1)
		for i := range dp {
			dp[i] = make([]int, n+2)
		}
		dp[0][0] = 1
		for i := 1; i <= n; i++ {
			w := a[i]
			for j := 0; j <= n; j++ {
				if w == 0 {
					if j > 0 || i <= p {
						dp[i][max(j-1, 0)] = (dp[i][max(j-1, 0)] + dp[i-1][j]) % mod
					}
				} else if w < v || w == v && i < p {
					dp[i][j+1] = (dp[i][j+1] + dp[i-1][j]) % mod
				} else {
					dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod
				}
				if i != p {
					dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod
				}
			}
		}
		s := int64(0)
		for _, fv := range dp[n] {
			s += int64(fv)
		}
		ans = (ans + s%mod*v) % mod
	}
	Fprint(out, ans)
}

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

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

package main

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

func debug(T ...interface{}) {
	fmt.Println(T...)
}

const N = 505
const mod = 998244353

var a [N]int
var b [N]int
var dp [N][N]int

var in = bufio.NewReader(os.Stdin)

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

func get(n int, p int) int {
	for i := 0; i <= n; i++ {
		for k := 0; k <= i; k++ {
			dp[i][k] = 0
		}
	}
	dp[0][0] = 1
	for i := 0; i < n; i++ {
		for k := 0; k <= i; k++ {
			if dp[i][k] == 0 {
				continue
			}
			dp[i+1][k] += dp[i][k]
			dp[i+1][k] %= mod
			if i+1 >= p && k+b[i+1] >= 0 {
				dp[i+1][k+b[i+1]] += dp[i][k]
				dp[i+1][k+b[i+1]] %= mod
			} else if i+1 < p {
				dp[i+1][max(k+b[i+1], 0)] += dp[i][k]
				dp[i+1][max(k+b[i+1], 0)] %= mod
			}
		}
	}
	ans := 0
	for k := 0; k <= n; k++ {
		ans += dp[n][k]
		ans %= mod
	}
	return ans
}

func solve(t int) {
	var n int
	fmt.Fscan(in, &n)
	var ch string
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &ch)
		if ch == "+" {
			fmt.Fscan(in, &a[i])
		} else {
			a[i] = -1
		}
	}
	ans := int64(0)
	for p := 1; p <= n; p++ {
		if a[p] != -1 {
			k := 0
			for i := 1; i <= n; i++ {
				if i == p {
					continue
				}
				k++
				if a[i] == -1 {
					b[k] = -1
				} else if a[i] < a[p] || (a[i] == a[p] && i < p) {
					b[k] = 1
				} else {
					b[k] = 0
				}
			}
			val := get(k, p)
			// debug(p, val)
			ans += int64(val) * int64(a[p])
			ans %= mod
		}
	}
	fmt.Println(ans)
}

func main() {
	var T int = 1
	// fmt.Fscan(in, &T)
	for t := 1; t <= T; t++ {
		solve(t)
	}
}

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func ReadSign() bool {
	in.Scan()
	if in.Bytes()[0] == '-' {
		return false
	}
	return true
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

const (
	N = 505
	M = 998244353
)

var (
	a [N]int
	f [N][N]int
)

func main() {
	defer out.Flush()
	n := Read()
	for i := 1; i <= n; i++ {
		if ReadSign() {
			a[i] = Read()
		}
	}
	s := 0
	for k := 0; k < n; k++ {
		if a[k] == 0 {
			continue
		}
		for i := 0; i <= n; i++ {
			for j := 0; j <= n; j++ {
				f[i][j] = 0
			}
		}
		f[0][0] = 1
		for i := 1; i <= n; i++ {
			if a[i] == 0 {
				if i < k {
					f[i][0] = (f[i][0] + f[i-1][0]) % M
				}
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j+1]) % M
				}
			} else if a[i] < a[k] || a[i] == a[k] && i < k {
				for j := 1; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j-1]) % M
				}
			} else {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
			if i != k {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
		}
		for i := 0; i <= n; i++ {
			s = (s + int((int64(f[n][i])*int64(a[k]))%int64(M))) % M
		}
	}
	Fprintln(out, s)
}

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func ReadSign() bool {
	in.Scan()
	if in.Bytes()[0] == '-' {
		return false
	}
	return true
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

const (
	N = 505
	M = 998244353
)

var (
	a [N]int
	f [N][N]int
)

func main() {
	defer out.Flush()
	n := Read()
	for i := 1; i <= n; i++ {
		if ReadSign() {
			a[i] = Read()
		}
	}
	s := 0
	for k := 0; k < n; k++ {
		if a[k] == 0 {
			continue
		}
		for i := 0; i <= n; i++ {
			for j := 0; j <= n; j++ {
				f[i][j] = 0
			}
		}
		f[0][0] = 1
		for i := 1; i <= n; i++ {
			if a[i] == 0 {
				if i < k {
					f[i][0] = (f[i][0] + f[i-1][0]) % M
				}
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j+1]) % M
				}
			} else if a[i] < a[k] || a[i] == a[k] && i < k {
				for j := 1; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j-1]) % M
				}
			} else {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
			if i != k {
				for j := 0; j <= i; j++ {
					f[i][j] = (f[i][j] + f[i-1][j]) % M
				}
			}
		}
		for i := 0; i <= n; i++ {
			s = (s + int((int64(f[n][i])*int64(a[k]))%M)) % M
		}
	}
	Fprintln(out, s)
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		S := make([]string, n)
		for i := 0; i < n; i++ {
			S[i], _ = reader.ReadString('\n')
		}
		res := solve(n, S)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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
}

const MOD = 998244353

func solve(n int, S []string) int {
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		if S[i][0] == '+' {
			readInt([]byte(S[i]), 2, &a[i+1])
		}
	}

	var ans int64

	f := make([][]int64, n+2)
	for i := 0; i <= n+1; i++ {
		f[i] = make([]int64, n+2)
	}

	for t := 1; t <= n; t++ {
		if a[t] == 0 {
			continue
		}
		for i := 0; i <= n+1; i++ {
			for j := 0; j <= n+1; j++ {
				f[i][j] = 0
			}
		}
		f[0][0] = 1
		for i := 1; i <= n; i++ {
			for j := 0; j <= i; j++ {
				if a[i] == 0 {
					// a minus
					if i <= t || j > 0 {
						f[i][max(j-1, 0)] = modAdd(f[i][max(j-1, 0)], f[i-1][j])
					}
				} else {
					if a[i] < a[t] || (a[i] == a[t] && i < t) {
						f[i][j+1] = modAdd(f[i][j+1], f[i-1][j])
					} else {
						f[i][j] = modAdd(f[i][j], f[i-1][j])
					}
				}

				if i != t {
					f[i][j] = modAdd(f[i][j], f[i-1][j])
				}
			}
		}

		for i := 0; i <= n; i++ {
			ans = modAdd(ans, f[n][i]*int64(a[t])%MOD)
		}
	}

	return int(ans)
}

func modAdd(a, b int64) int64 {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1542D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod = 998244353

	var n int
	var op string
	Fscan(in, &n)
	a := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		if Fscan(in, &op); op == "+" {
			Fscan(in, &a[i])
		}
	}

	ans := int64(0)
	for p := 1; p <= n; p++ {
		v := a[p]
		if v == 0 {
			continue
		}
		dp := make([][]int, n+1)
		for i := range dp {
			dp[i] = make([]int, n+2)
		}
		dp[0][0] = 1
		for i := 1; i <= n; i++ {
			w := a[i]
			for j := 0; j <= n; j++ {
				if w == 0 {
					if j > 0 || i <= p {
						dp[i][max(j-1, 0)] = (dp[i][max(j-1, 0)] + dp[i-1][j]) % mod
					}
				} else if w < v || w == v && i < p {
					dp[i][j+1] = (dp[i][j+1] + dp[i-1][j]) % mod
				} else {
					dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod
				}
				if i != p {
					dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod
				}
			}
		}
		s := int64(0)
		for _, fv := range dp[n] {
			s += int64(fv)
		}
		ans = (ans + s*v) % mod
	}
	Fprint(out, ans)
}

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

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


Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.Your task is to find the number of successful students in the group.

The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of students and the number of subjects, correspondingly. Next n lines each containing m characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.

Print the single number — the number of successful students in the given group.

NoteIn the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.In the second sample test each student is the best at at least one subject.

package main

import "fmt"

func main() {
    var n,m int
    var s [105]string
    var max [105]byte
    fmt.Scan(&n,&m)
    for i := 0; i < n; i++ {
        fmt.Scan(&s[i])
        for j := 0; j < m; j++ {
            if max[j] < s[i][j] { max[j] = s[i][j] }
        }
    }
    ans := 0
    for i := 0; i < n; i++ {
        success := false
        for j := 0; j < m; j++ {
            if s[i][j] == max[j] { success = true; break }
        }
        if success { ans++ }
    }
    fmt.Println(ans)
}

package main

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

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

	success := 0
	bests := make([]int, m)
	gradebook := make([][]int, n)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	for i := 0; i < n; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			s = re.ReplaceAllString(s, "")

			gradebook[i] = make([]int, m)
			for j := 0; j < m; j++ {
				g := int(s[j] - '0')
				gradebook[i][j] = g
				if bests[j] < g {
					bests[j] = g
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if gradebook[i][j] == bests[j] {
				success++
				break
			}
		}
	}

	fmt.Println(success)
}

package main

import "fmt"

func main() {
    var n,m int      // membuat variabel n dan m dengan jenis int
    var s [105]string  // membuat variabel s dengan array berjumlah 105 dan berjenis string
    var max [105]byte   // membuat variabel max dengan array berjumlah 105 dan berjenis byte
    fmt.Scan(&n,&m)   // mengambil input
    for i := 0; i < n; i++ {   // looping
        fmt.Scan(&s[i])    // mengambil input kedua
        for j := 0; j < m; j++ {   // looping kedua
            if max[j] < s[i][j] { max[j] = s[i][j] }  // jika array max elemen ke j kurang dari array s elemen i dan j,maka array max elemen ke j sama dengan s array elemen i dan j
        }
    }
    ans := 0    // membuat variabel ans dan kemudian diisi dengan 0
    for i := 0; i < n; i++ {  // looping kedua
        success := false   // membuat variabel succes dan kemudian diisi dengan false
        for j := 0; j < m; j++ {   // looping ketiga
            if s[i][j] == max[j] { success = true; break }  // jika array s elemen i dan j sama dengan array max elemen j maka success sama dengan true kemudian keluar dari fungsi
        }
        if success { ans++ }  // jika success maka ans di tambah
    }
    fmt.Println(ans)    // cetak hasil
}

package main

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

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

	scss := make(map[int]bool)
	stds := make([]string, std)
	for i := 0; i < std; i++ {
		fmt.Fscan(reader, &stds[i])
	}

	for i := 0; i < sbj; i++ {
		mx, scs := 0, []int{}
		for j := 0; j < std; j++ {
			no, _ := strconv.Atoi(string(stds[j][i]))
			if no > mx {
				mx = no
				scs = nil
				scs = append(scs, j)
			}
			if no == mx {
				scs = append(scs, j)
			}

		}

		for _, x := range scs {
			scss[x] = true
		}
	}

	fmt.Println(len(scss))
}


You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right.You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.How many operations will you need to perform until the next operation does not have any points to delete?

Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc. The number of the points is between 1 and 106.

Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

NoteIn the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second uint8
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var seg []pair

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var s string
	fmt.Fscanf(in, "%s\n", &s)
	n := len(s)
	prev := 0
	for i := 1; i < n; i++ {
		if s[i] != s[i - 1] {
			seg = append(seg, pair{i - prev, s[i - 1]})
			prev = i
		}
	}
	seg = append(seg, pair{n - prev, s[n - 1]})
	ans := 0
	for ;; {
		numOp := 100000000
		for i := range seg {
			length := seg[i].first
			if i == 0 || i == len(seg) - 1 {
				numOp = min(numOp, length)
			} else {
				numOp = min(numOp, (length >> 1) + (length & 1))
			}
		}
		if len(seg) <= 1 {
			break
		}
		ans += numOp
		tmpSeg := make([]pair,0)
		length := -1
		var character uint8
		for i := range seg {
			necessaryToDelete := 0
			deleted := 0
			l := seg[i].first
			if i == 0 || i == len(seg) - 1 {
				necessaryToDelete = l
			} else {
				necessaryToDelete = (l >> 1) + (l & 1)
			}
			if numOp != necessaryToDelete {
				if i == 0 || i == len(seg) - 1 {
					deleted = numOp
				} else {
					deleted = numOp * 2
				}
				if length == -1 {
					length = seg[i].first - deleted
					character = seg[i].second
				} else {
					if seg[i].second == character {
						length += (seg[i].first- deleted)
					} else {
						tmpSeg = append(tmpSeg, pair{length, character})
						length = seg[i].first - deleted
						character = seg[i].second
					}
				}
			}
		}
		tmpSeg = append(tmpSeg, pair{length, character})
		//fmt.Println(tmpSeg)
		seg = nil
		for i := range tmpSeg {
			seg = append(seg, tmpSeg[i])
		}
	}
	fmt.Println(ans)
}

package main

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

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

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

func toInt(buf []byte) (o int) {
	for _, v := range buf {
		o = o*10 + int(v-'0')
	}
	return
}

type pair struct {
	first int
	second uint8
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var seg []pair

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var s string
	fmt.Fscanf(in, "%s\n", &s)
	n := len(s)
	prev := 0
	for i := 1; i < n; i++ {
		if s[i] != s[i - 1] {
			seg = append(seg, pair{i - prev, s[i - 1]})
			prev = i
		}
	}
	seg = append(seg, pair{n - prev, s[n - 1]})
	ans := 0
	for ;; {
		numOp := 100000000
		for i := range seg {
			length := seg[i].first
			if i == 0 || i == len(seg) - 1 {
				numOp = min(numOp, length)
			} else {
				numOp = min(numOp, (length >> 1) + (length & 1))
			}
		}
		if len(seg) <= 1 {
			break
		}
		ans += numOp
		tmpSeg := make([]pair,0)
		length := 0
		var character uint8
		for i := range seg {
			necessaryToDelete := 0
			l := seg[i].first
			if i == 0 || i == len(seg) - 1 {
				necessaryToDelete = l
			} else {
				necessaryToDelete = (l >> 1) + (l & 1)
			}
			if numOp != necessaryToDelete {
				if len(tmpSeg) == 0 {
					length = seg[i].first
					character = seg[i].second
				} else {
					if seg[i].second == character {
						length += seg[i].first
					} else {
						tmpSeg = append(tmpSeg, pair{length, character})
						length = seg[i].first
						character = seg[i].second
					}
				}
			}
		}
		tmpSeg = append(tmpSeg, pair{length, character})
		seg = nil
		for i := range tmpSeg {
			seg = append(seg, tmpSeg[i])
		}
	}
	fmt.Println(ans)
}


Vasya has his favourite number $$$n$$$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $$$d_1, d_2, \ldots, d_k$$$, such that $$$1 \leq d_i \leq 9$$$ for all $$$i$$$ and $$$d_1 + d_2 + \ldots + d_k = n$$$.Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among $$$d_1, d_2, \ldots, d_k$$$. Help him!

The first line contains a single integer $$$n$$$ — the number that Vasya wants to split ($$$1 \leq n \leq 1000$$$).

In the first line print one integer $$$k$$$ — the number of digits in the partition. Note that $$$k$$$ must satisfy the inequality $$$1 \leq k \leq n$$$. In the next line print $$$k$$$ digits $$$d_1, d_2, \ldots, d_k$$$ separated by spaces. All digits must satisfy the inequalities $$$1 \leq d_i \leq 9$$$. You should find a partition of $$$n$$$ in which the number of different digits among $$$d_1, d_2, \ldots, d_k$$$ will be minimal possible among all partitions of $$$n$$$ into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number $$$n$$$ into digits.

NoteIn the first test, the number $$$1$$$ can be divided into $$$1$$$ digit equal to $$$1$$$.In the second test, there are $$$3$$$ partitions of the number $$$4$$$ into digits in which the number of different digits is $$$1$$$. This partitions are $$$[1, 1, 1, 1]$$$, $$$[2, 2]$$$ and $$$[4]$$$. Any of these partitions can be found. And, for example, dividing the number $$$4$$$ to the digits $$$[1, 1, 2]$$$ isn't an answer, because it has $$$2$$$ different digits, that isn't the minimum possible number.

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(n)
	for i:= 1; i<= n; i++ {
		fmt.Print("1 ")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Print(n, "\n"+strings.Repeat("1 ", n))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fprintf(out, "%d\n", n)
	for i := 0; i < n-1; i++ {
		fmt.Fprintf(out, "1 ")
	}
	fmt.Fprintf(out, "1\n")
	return
}

package main

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

func min(a,b int)int {
    var res int
    if a<b {
        res=a
    } else {
        res=b;
    }
    return res;
}

func solve(){
    var n,i int
    n=readInt()
    fmt.Println(n)
    for i=0;i<n;i++{
        fmt.Print("1 ")
    }
    fmt.Println("")
}

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 (
	"bufio"
	"fmt"
	"os"
)

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	fmt.Printf("%d\n",n)
	for i := 0; i < n; i++ {
		fmt.Printf("1 ")
	}
	fmt.Printf("\n")
}

package main

import "fmt"

func main(){

	var n int32
	var i int32 = 1

	fmt.Scanf("%d",&n)

	fmt.Println(n)

	for i<=n {
		fmt.Print(1," ")
		i++
	}

}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	isDivisible := false
	divDigit := 1
	switch {

	case k%9 == 0:
		isDivisible = true
		divDigit = 9
	case k%8 == 0:
		isDivisible = true
		divDigit = 8
	case k%7 == 0:
		isDivisible = true
		divDigit = 7
	case k%6 == 0:
		isDivisible = true
		divDigit = 6
	case k%5 == 0:
		isDivisible = true
		divDigit = 5
	case k%4 == 0:
		isDivisible = true
		divDigit = 4
	case k%3 == 0:
		isDivisible = true
		divDigit = 3
	case k%2 == 0:
		isDivisible = true
		divDigit = 2
	default:
		isDivisible = true
		divDigit = 1
	}

	count := k/divDigit
	if isDivisible {
		fmt.Println(count)
	//} else {
		//fmt.Println(count+1)
		//fmt.Printf("%d ", k%divDigit)
	}
	for i:=0; i< count ; i++  {
		fmt.Printf("%d ", divDigit)
	}
	fmt.Println()
	return

	}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	var n int
	fmt.Scan(&n)

	for k := 9; k > 0; k-- {
		if n%k == 0 {
			p := n/k
			fmt.Println(p)
			for i := 0; i < p; i++ {
				fmt.Printf("%d ", k)
			}
			return
		}
	}
}

package main

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

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

	var n int

	fmt.Fscan(reader, &n)

	fmt.Println(n, "\n"+strings.Repeat("1 ", n))

	return
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	if k < 10 {
		fmt.Println("1")
		fmt.Println(k)
		return
	}
	isDivisible := false
	divDigit := 1
	switch {

	case k%9 == 0:
		isDivisible = true
		divDigit = 9
	case k%8 == 0:
		isDivisible = true
		divDigit = 8
	case k%7 == 0:
		isDivisible = true
		divDigit = 7
	case k%6 == 0:
		isDivisible = true
		divDigit = 6
	case k%5 == 0:
		isDivisible = true
		divDigit = 5
	case k%4 == 0:
		isDivisible = true
		divDigit = 4
	case k%3 == 0:
		isDivisible = true
		divDigit = 3
	case k%2 == 0:
		isDivisible = true
		divDigit = 2
	default:
		divDigit = 9
	}

	count := k/divDigit
	if isDivisible {
		fmt.Println(count)
	} else {
		fmt.Println(count+1)
		fmt.Printf("%d ", k%divDigit)
	}
	for i:=0; i< count ; i++  {
		fmt.Printf("%d ", divDigit)
	}
	fmt.Println()
	return

	}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	k, _ := strconv.Atoi(s.Text())

	isDivisible := false
	divDigit := 1
	switch {

	case k%9 == 0:
		isDivisible = true
		divDigit = 9
	case k%8 == 0:
		isDivisible = true
		divDigit = 8
	case k%7 == 0:
		isDivisible = true
		divDigit = 7
	case k%6 == 0:
		isDivisible = true
		divDigit = 6
	case k%5 == 0:
		isDivisible = true
		divDigit = 5
	case k%4 == 0:
		isDivisible = true
		divDigit = 4
	case k%3 == 0:
		isDivisible = true
		divDigit = 3
	case k%2 == 0:
		isDivisible = true
		divDigit = 2
	default:
		isDivisible = true
		divDigit = 1
	}

	count := k/divDigit
	if isDivisible {
		fmt.Println(count)
	//} else {
		//fmt.Println(count+1)
		fmt.Printf("%d ", k%divDigit)
	}
	for i:=0; i< count ; i++  {
		fmt.Printf("%d ", divDigit)
	}
	fmt.Println()
	return

	}