This is an easier version of the problem. In this version $$$n \le 1000$$$The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought $$$n$$$ plots along the highway and is preparing to build $$$n$$$ skyscrapers, one skyscraper per plot.Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.Formally, let's number the plots from $$$1$$$ to $$$n$$$. Then if the skyscraper on the $$$i$$$-th plot has $$$a_i$$$ floors, it must hold that $$$a_i$$$ is at most $$$m_i$$$ ($$$1 \le a_i \le m_i$$$). Also there mustn't be integers $$$j$$$ and $$$k$$$ such that $$$j < i < k$$$ and $$$a_j > a_i < a_k$$$. Plots $$$j$$$ and $$$k$$$ are not required to be adjacent to $$$i$$$.The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of plots. The second line contains the integers $$$m_1, m_2, \ldots, m_n$$$ ($$$1 \leq m_i \leq 10^9$$$) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.

Print $$$n$$$ integers $$$a_i$$$ — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible. If there are multiple answers possible, print any of them.

NoteIn the first example, you can build all skyscrapers with the highest possible height.In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer $$$[10, 6, 6]$$$ is optimal. Note that the answer of $$$[6, 6, 8]$$$ also satisfies all restrictions, but is not optimal.

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		best := int64(0)
		ans := -1
		for i := 0; i < n; i++ {
			//chose i as peek
			curAns := int64(a[i])
			tmp := a[i]
			for j := i - 1; j >= 0; j-- {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += int64(tmp)
			}
			tmp = a[i]
			for j := i + 1; j < n; j++ {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += int64(tmp)
			}
			if ans == -1 || best < curAns {
				ans = i
				best = curAns
			}
		}
		for i := ans - 1; i >= 0; i-- {
			if a[i] > a[i+1] {
				a[i] = a[i+1]
			}
		}
		for i := ans + 1; i < n; i++ {
			if a[i] > a[i-1] {
				a[i] = a[i-1]
			}
		}
		fmt.Fprintf(out, "%d", a[0])
		for i := 1; i < n; i++ {
			fmt.Fprintf(out, " %d", a[i])
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

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
}

var partialSum []int64

type Tree struct {
	a     []int64
	incr  []int
	fixed []int
	sz    int
}

func (t *Tree) Upd(v int) {
	if v < t.sz {
		t.a[v] = t.a[v<<1] + t.a[(v<<1)|1]
	}
}

func (t *Tree) Propagate(v int, l, r int) {
	prp := t.fixed[v]
	if prp >= 0 {
		if v < t.sz {
			t.fixed[v<<1] = prp
			t.fixed[(v<<1)|1] = prp
			t.incr[v<<1] = 0
			t.incr[(v<<1)|1] = 0
		}
		t.a[v] = 0
		t.fixed[v] = -1
	}

	prp = t.incr[v]
	if prp > 0 {
		if v < t.sz {
			t.incr[v<<1] += prp
			t.incr[(v<<1)|1] += prp
		}
		t.a[v] += int64(prp) * (partialSum[r+1] - partialSum[l])
		t.incr[v] = 0
	}
}

func (t *Tree) GoAdd(v, fixed, incr, l, r, L, R int) {
	t.Propagate(v, L, R)
	if l > r {
		return
	}
	if r < L || l > R {
		return
	}
	if l <= L && R <= r {
		if fixed >= 0 {
			t.fixed[v] = fixed
			t.incr[v] = 0
			t.Propagate(v, L, R)
		}
		t.incr[v] += incr
		t.Propagate(v, L, R)
		return
	}
	t.GoAdd(v<<1, fixed, incr, l, r, L, (L+R)>>1)
	t.GoAdd((v<<1)|1, fixed, incr, l, r, (L+R)/2+1, R)
	t.Upd(v)
}

func (t *Tree) GoSum(v, l, r, L, R int) int64 {
	t.Propagate(v, L, R)
	if l > r {
		return int64(0)
	}
	if r < L || l > R {
		return int64(0)
	}
	if l <= L && R <= r {
		return t.a[v]
	}
	r1 := t.GoSum(v<<1, l, r, L, (L+R)>>1)
	r2 := t.GoSum((v<<1)|1, l, r, (L+R)/2+1, R)
	t.Upd(v)
	return r1 + r2
}

func (t *Tree) Add(l, r int, fixed int, incr int) {
	l = max(l, 0)
	r = min(r, t.sz-1)
	if l > r {
		return
	}
	t.GoAdd(1, fixed, incr, l, r, 0, t.sz-1)
}

func (t *Tree) Sum(l, r int) int64 {
	if l > r {
		return 0
	}
	res := t.GoSum(1, l, r, 0, t.sz-1)
	return res
}

func NewTree(n int) *Tree {
	sz := 1
	for sz < n {
		sz <<= 1
	}
	a := make([]int64, 2*sz+1)
	incr := make([]int, 2*sz+1)
	fixed := make([]int, 2*sz+1)
	return &Tree{a, fixed, incr, sz}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n := NextInt()
	m := make([]int, n)
	sorted := make([]int, n)
	for i := 0; i < n; i++ {
		m[i] = NextInt()
		sorted[i] = m[i]
	}
	sort.Ints(sorted)
	// newLen := 0
	// for i := 0; i < n; i++ {
	// 	if newLen == 0 || sorted[newLen-1] != sorted[i] {
	// 		sorted[newLen] = sorted[i]
	// 		newLen++
	// 	}
	// }
	// sorted = sorted[:newLen]
	// partialSum = make([]int64, len(sorted)+1)
	// partialSum[0] = 0
	// for i := 1; i <= len(sorted); i++ {
	// 	partialSum[i] = partialSum[i-1] + int64(sorted[i-1])
	// }

	stack := make([]int, n)
	add := make([]int64, n)
	len := 0
	left := make([]int64, n)
	var sum int64
	for i := 0; i < n; i++ {
		for len > 0 && m[stack[len-1]] > m[i] {
			sum -= add[len-1]
			len--
		}
		if len > 0 {
			add[len] = int64(i-stack[len-1]) * int64(m[i])
		} else {
			add[len] = int64(i+1) * int64(m[i])
		}
		sum += add[len]
		left[i] = sum
		stack[len] = i
		// stderr("left", i, "=", sum)
		len++
	}

	len = 0
	right := make([]int64, n)
	sum = 0
	for i := n - 1; i >= 0; i-- {
		for len > 0 && m[stack[len-1]] > m[i] {
			sum -= add[len-1]
			len--
		}
		if len > 0 {
			add[len] = int64(stack[len-1]-i) * int64(m[i])
		} else {
			add[len] = int64(n-i) * int64(m[i])
		}
		sum += add[len]
		right[i] = sum
		stack[len] = i
		len++
		// stderr("right", i, "=", sum)
	}
	// tree := NewTree(newLen)
	// left := make([]int64, n)
	// right := make([]int64, n)
	// for i := 0; i < n; i++ {
	// 	pos:= sort.SearchInts(sorted, m[i])
	// 	tree.Add(0, pos, -1, 1)
	// 	tree.Add(pos+1, len(sorted)-1, 0, 0)
	// 	left[i] = tree.Sum(0, pos)
	// 	// stderr("left", i, left[i])
	// }
	// tree = NewTree(newLen)
	// for i := n - 1; i >= 0; i-- {
	// 	pos := sort.SearchInts(sorted, m[i])
	// 	tree.Add(0, pos, -1, 1)
	// 	tree.Add(pos+1, len(sorted)-1, 0, 0)
	// 	right[i] = tree.Sum(0, pos)
	// 	// stderr("right", i, right[i])
	// }

	var res int64
	var resI int

	for i := 0; i < n; i++ {
		if i == 0 || left[i]+right[i]-int64(m[i]) > res {
			res = left[i] + right[i] - int64(m[i])
			resI = i
		}
	}

	// stderr("resi", resI, "sum", res)

	resarrr := make([]int, n)
	resarrr[resI] = m[resI]

	for i := resI - 1; i >= 0; i-- {
		resarrr[i] = resarrr[i+1]
		if m[i] < resarrr[i] {
			resarrr[i] = m[i]
		}
	}
	for i := resI + 1; i < n; i++ {
		resarrr[i] = resarrr[i-1]
		if m[i] < resarrr[i] {
			resarrr[i] = m[i]
		}
	}

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

package main

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

func main() {
	var plots int
	fmt.Scanf("%d\n", &plots)
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	arrs := strings.Split(string(line), " ")
	arr := make([]int64, plots)
	for i, c := range arrs {
		arr[i], _ = strconv.ParseInt(c, 10, 64)
	}
	_, result := getMaxFloors(arr, arr, 0, plots-1)
	for i:=0;i<len(result);i++ {
		fmt.Printf("%d ", result[i])
	}
}

func getMaxFloors(arr, current []int64, start, end int) (int64, []int64) {
	if start == end {
		return arr[start], current
	}
	if start > end {
		return 0, current
	}
	minI, minV := start, arr[start]
	for i := start+1; i <= end; i++ {
		if arr[i] < minV {
			minI = i
			minV = arr[i]
		}
	}
	// fmt.Println(minI, minV, start, end)
	current1 := make([]int64, len(current))
	copy(current1, current)
	for i:=start;i<=minI;i++ {
		current1[i] = minV
	}
	r1, temp1:= getMaxFloors(arr, current1, minI+1, end)
	r1 += int64((minI - start + 1))*minV

	current2 := make([]int64, len(current))
	copy(current2, current)
	for i:=minI;i<=end;i++ {
		current2[i] = minV
	}
	r2, temp2 := getMaxFloors(arr, current2, start, minI-1)
	r2 += int64(end - minI + 1)*minV
	if r1 > r2 {
		// fmt.Println(r1, temp1)
		return r1, temp1
	}
	//fmt.Println(r2, temp2)
	return r2, temp2
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	maxh := int64(0)
	maxPos := 0
	for i, top := range a {
		cnt := int64(0)
		tmpMax := top
		for j := i; j >= 0; j-- {
			tmpMax = min(tmpMax, a[j])
			cnt += tmpMax
		}
		tmpMax = top
		for j := i + 1; j < n; j++ {
			tmpMax = min(tmpMax, a[j])
			cnt += tmpMax
		}
		if cnt > maxh {
			maxh = cnt
			maxPos = i
		}
	}

	ans := make([]int64, n)
	ans[maxPos] = a[maxPos]

	top := a[maxPos]
	tmpMax := top
	for j := maxPos; j >= 0; j-- {
		tmpMax = min(tmpMax, a[j])
		ans[j] = tmpMax
	}
	tmpMax = top
	for j := maxPos + 1; j < n; j++ {
		tmpMax = min(tmpMax, a[j])
		ans[j] = tmpMax

	}
	for i, v := range ans {
		if i > 0 {
			Fprint(out, " ")
		}
		Fprint(out, v)
	}
}

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

package main

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

func touint64(buf []byte) uint64 {
	n := uint64(0)
	for _, v := range buf {
		n = n*10 + uint64(v-'0')
	}

	return n
}

func readData() []uint64 {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n := touint64(scanner.Bytes())

	r := make([]uint64, n)
	for i := range r {
		scanner.Scan()
		r[i] = touint64(scanner.Bytes())
	}

	return r
}

func solve(heights []uint64) []uint64 {
	L := len(heights)
	res, t := make([]uint64, L), make([]uint64, L)

	var max uint64

	for i := 0; i < L; i++ {
		copy(t, heights)

		s := t[i]

		for j := i - 1; j >= 0; j-- {
			if t[j] > t[j+1] {
				t[j] = t[j+1]
			}
			s += t[j]
		}

		for j := i + 1; j < L; j++ {
			if t[j] > t[j-1] {
				t[j] = t[j-1]
			}
			s += t[j]
		}

		if s > max {
			max = s
			copy(res, t)
		}
	}

	return res
}

func main() {
	heights := readData()
	heights = solve(heights)

	for _, h := range heights {
		fmt.Printf("%d ", h)
	}
	fmt.Println()
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		best := 0
		ans := -1
		for i := 0; i < n; i++ {
			//chose i as peek
			curAns := a[i]
			tmp := a[i]
			for j := i - 1; j >= 0; j-- {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			tmp = a[i]
			for j := i + 1; j < n; j++ {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			if ans == -1 || best < curAns {
				ans = i
				best = curAns
			}
		}
		for i := ans - 1; i >= 0; i-- {
			if a[i] > a[i+1] {
				a[i] = a[i+1]
			}
		}
		for i := ans + 1; i < n; i++ {
			if a[i] > a[i-1] {
				a[i] = a[i-1]
			}
		}
		fmt.Fprintf(out, "%d", a[0])
		for i := 1; i < n; i++ {
			fmt.Fprintf(out, " %d", a[i])
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		best := 0
		ans := -1
		for i := 0; i < n; i++ {
			//chose i as peek
			curAns := a[i]
			tmp := a[i]
			for j := i - 1; j >= 0; j-- {
				if tmp < a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			for j := i + 1; j < n; j++ {
				if tmp < a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			if ans == -1 || best < curAns {
				ans = i
				best = curAns
			}
		}
		for i := ans - 1; i >= 0; i-- {
			if a[i] > a[i+1] {
				a[i] = a[i+1]
			}
		}
		for i := ans + 1; i < n; i++ {
			if a[i] > a[i-1] {
				a[i] = a[i-1]
			}
		}
		fmt.Fprintf(out, "%d", a[0])
		for i := 1; i < n; i++ {
			fmt.Fprintf(out, " %d", a[i])
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		best := 0
		ans := -1
		for i := 0; i < n; i++ {
			//chose i as peek
			curAns := a[i]
			tmp := a[i]
			for j := i - 1; j >= 0; j-- {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			for j := i + 1; j < n; j++ {
				if tmp > a[j] {
					tmp = a[j]
				}
				curAns += tmp
			}
			if ans == -1 || best < curAns {
				ans = i
				best = curAns
			}
		}
		for i := ans - 1; i >= 0; i-- {
			if a[i] > a[i+1] {
				a[i] = a[i+1]
			}
		}
		for i := ans + 1; i < n; i++ {
			if a[i] > a[i-1] {
				a[i] = a[i-1]
			}
		}
		fmt.Fprintf(out, "%d", a[0])
		for i := 1; i < n; i++ {
			fmt.Fprintf(out, " %d", a[i])
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

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
}

var partialSum []int64

type Tree struct {
	a     []int64
	incr  []int
	fixed []int
	sz    int
}

func (t *Tree) Upd(v int) {
	if v < t.sz {
		t.a[v] = t.a[v<<1] + t.a[(v<<1)|1]
	}
}

func (t *Tree) Propagate(v int, l, r int) {
	prp := t.fixed[v]
	if prp >= 0 {
		if v < t.sz {
			t.fixed[v<<1] = prp
			t.fixed[(v<<1)|1] = prp
			t.incr[v<<1] = 0
			t.incr[(v<<1)|1] = 0
		}
		t.a[v] = 0
		t.fixed[v] = -1
	}

	prp = t.incr[v]
	if prp > 0 {
		if v < t.sz {
			t.incr[v<<1] += prp
			t.incr[(v<<1)|1] += prp
		}
		t.a[v] += int64(prp) * (partialSum[r+1] - partialSum[l])
		t.incr[v] = 0
	}
}

func (t *Tree) GoAdd(v, fixed, incr, l, r, L, R int) {
	t.Propagate(v, L, R)
	if l > r {
		return
	}
	if r < L || l > R {
		return
	}
	if l <= L && R <= r {
		if fixed >= 0 {
			t.fixed[v] = fixed
			t.incr[v] = 0
			t.Propagate(v, L, R)
		}
		t.incr[v] += incr
		t.Propagate(v, L, R)
		return
	}
	t.GoAdd(v<<1, fixed, incr, l, r, L, (L+R)>>1)
	t.GoAdd((v<<1)|1, fixed, incr, l, r, (L+R)/2+1, R)
	t.Upd(v)
}

func (t *Tree) GoSum(v, l, r, L, R int) int64 {
	t.Propagate(v, L, R)
	if l > r {
		return int64(0)
	}
	if r < L || l > R {
		return int64(0)
	}
	if l <= L && R <= r {
		return t.a[v]
	}
	r1 := t.GoSum(v<<1, l, r, L, (L+R)>>1)
	r2 := t.GoSum((v<<1)|1, l, r, (L+R)/2+1, R)
	t.Upd(v)
	return r1 + r2
}

func (t *Tree) Add(l, r int, fixed int, incr int) {
	l = max(l, 0)
	r = min(r, t.sz-1)
	if l > r {
		return
	}
	t.GoAdd(1, fixed, incr, l, r, 0, t.sz-1)
}

func (t *Tree) Sum(l, r int) int64 {
	if l > r {
		return 0
	}
	res := t.GoSum(1, l, r, 0, t.sz-1)
	return res
}

func NewTree(n int) *Tree {
	sz := 1
	for sz < n {
		sz <<= 1
	}
	a := make([]int64, 2*sz+1)
	incr := make([]int, 2*sz+1)
	fixed := make([]int, 2*sz+1)
	return &Tree{a, fixed, incr, sz}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n := NextInt()
	m := make([]int, n)
	sorted := make([]int, n)
	for i := 0; i < n; i++ {
		m[i] = NextInt()
		sorted[i] = m[i]
	}
	sort.Ints(sorted)
	newLen := 0
	for i := 0; i < n; i++ {
		if newLen == 0 || sorted[newLen-1] != sorted[i] {
			sorted[newLen] = sorted[i]
			newLen++
		}
	}
	sorted = sorted[:newLen]
	partialSum = make([]int64, len(sorted)+1)
	partialSum[0] = 0
	for i := 1; i <= len(sorted); i++ {
		partialSum[i] = partialSum[i-1] + int64(sorted[i-1])
	}
	tree := NewTree(newLen)
	left := make([]int64, n)
	right := make([]int64, n)
	for i := 0; i < n; i++ {
		pos := sort.SearchInts(sorted, m[i])
		tree.Add(0, pos, -1, 1)
		tree.Add(pos+1, len(sorted), 0, 0)
		left[i] = tree.Sum(0, pos)
		// stderr("left", i, left[i])
	}
	tree = NewTree(newLen)
	for i := n - 1; i >= 0; i-- {
		pos := sort.SearchInts(sorted, m[i])
		tree.Add(0, pos, -1, 1)
		tree.Add(pos+1, len(sorted), 0, 0)
		right[i] = tree.Sum(0, pos)
		// stderr("right", i, right[i])
	}

	var res int64
	var resI int

	for i := 0; i < n; i++ {
		if i == 0 || left[i]+right[i]-int64(m[i]) > res {
			res = left[i] + right[i] - int64(m[i])
			resI = i
		}
	}

	// stderr("resi", resI)

	resarrr := make([]int, n)
	resarrr[resI] = m[resI]

	for i := resI - 1; i >= 0; i-- {
		resarrr[i] = resarrr[i+1]
		if m[i] < resarrr[i] {
			resarrr[i] = m[i]
		}
	}
	for i := resI + 1; i < n; i++ {
		resarrr[i] = resarrr[i-1]
		if m[i] < resarrr[i] {
			resarrr[i] = m[i]
		}
	}

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

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

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
}

type Tree struct {
	a     []int64
	incr  []int
	fixed []int
	sz    int
}

func (t *Tree) Upd(v int) {
	if v < t.sz {
		t.a[v] = t.a[v<<1] + t.a[(v<<1)|1]
	}
}

func (t *Tree) Propagate(v int, l, r int) {
	prp := t.fixed[v]
	if prp >= 0 {
		if v < t.sz {
			t.fixed[v<<1] = prp
			t.fixed[(v<<1)|1] = prp
			t.incr[v<<1] = 0
			t.incr[(v<<1)|1] = 0
		}
		t.a[v] = 0
		t.fixed[v] = -1
	}

	prp = t.incr[v]
	if prp > 0 {
		if v < t.sz {
			t.incr[v<<1] += prp
			t.incr[(v<<1)|1] += prp
		}
		t.a[v] += int64(prp) * int64(l+r) * int64(l+r-1) / int64(2)
		t.incr[v] = 0
	}
}

func (t *Tree) GoAdd(v, fixed, incr, l, r, L, R int) {
	t.Propagate(v, L, R)
	if l > r {
		return
	}
	if r < L || l > R {
		return
	}
	if l <= L && R <= r {
		t.fixed[v] = fixed
		t.Propagate(v, L, R)
		t.incr[v] += incr
		t.Propagate(v, L, R)
		return
	}
	t.GoAdd(v<<1, fixed, incr, l, r, L, (L+R)>>1)
	t.GoAdd((v<<1)|1, fixed, incr, l, r, (L+R)/2+1, R)
	t.Upd(v)
}

func (t *Tree) GoSum(v, l, r, L, R int) int64 {
	t.Propagate(v, L, R)
	if l > r {
		return int64(0)
	}
	if r < L || l > R {
		return int64(0)
	}
	if l <= L && R <= r {
		return t.a[v]
	}
	r1 := t.GoSum(v<<1, l, r, L, (L+R)>>1)
	r2 := t.GoSum((v<<1)|1, l, r, (L+R)/2+1, R)
	t.Upd(v)
	return r1 + r2
}

func (t *Tree) Add(l, r int, fixed int, incr int) {
	l = max(l, 0)
	r = min(r, t.sz-1)
	if l > r {
		return
	}
	t.GoAdd(1, fixed, incr, l, r, 0, t.sz-1)
}

func (t *Tree) Sum(l, r int) int64 {
	if l > r {
		return 0
	}
	res := t.GoSum(1, l, r, 0, t.sz-1)
	return res
}

func NewTree(n int) *Tree {
	sz := 1
	for sz < n {
		sz <<= 1
	}
	a := make([]int64, 2*sz+1)
	incr := make([]int, 2*sz+1)
	fixed := make([]int, 2*sz+1)
	return &Tree{a, fixed, incr, sz}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n := NextInt()
	m := make([]int, n)
	sorted := make([]int, n)
	for i := 0; i < n; i++ {
		m[i] = NextInt()
		sorted[i] = m[i]
	}
	sort.Ints(sorted)
	newLen := 0
	for i := 0; i < n; i++ {
		if newLen == 0 || sorted[newLen-1] != sorted[i] {
			sorted[newLen] = sorted[i]
			newLen++
		}
	}
	sorted = sorted[:newLen]
	tree := NewTree(newLen)
	left := make([]int64, n)
	right := make([]int64, n)
	for i := 0; i < n; i++ {
		pos := sort.SearchInts(sorted, m[i])
		tree.Add(0, pos, -1, 1)
		tree.Add(pos+1, len(sorted), 0, 0)
		left[i] = tree.Sum(0, pos)
	}
	tree = NewTree(newLen)
	for i := n - 1; i >= 0; i-- {
		pos := sort.SearchInts(sorted, m[i])
		tree.Add(0, pos, -1, 1)
		tree.Add(pos+1, len(sorted), 0, 0)
		right[i] = tree.Sum(0, pos)
	}

	var res int64
	var resI int

	for i := 0; i < n; i++ {
		if i == 0 || left[i]+right[i]-int64(m[i]) > res {
			res = left[i] + right[i] - int64(m[i])
			resI = i
		}
	}
	lv := make([]int, n)
	lsince := make([]int, n)
	llen := 0
	for i := 0; i <= resI; i++ {
		for llen > 0 && lv[llen-1] > m[i] {
			llen--
		}
		lv[llen] = m[i]
		lsince[llen] = i
		llen++
	}
	rv := make([]int, n)
	rsince := make([]int, n)
	rlen := 0
	for i := n - 1; i >= resI; i-- {
		for rlen > 0 && rv[rlen-1] > m[i] {
			rlen--
		}
		rv[rlen] = m[i]
		rsince[rlen] = i
		rlen++
	}
	resarrr := make([]int, n)
	for i, j := 0, 0; i <= resI; i++ {
		for j < llen && i > lsince[j] {
			j++
		}
		resarrr[i] = lv[j]
	}

	for i, j := n-1, 0; i > resI; i-- {
		for j < rlen && i < rsince[j] {
			j++
		}
		resarrr[i] = rv[j]
	}

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

package main

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

func main() {
	var plots int
	fmt.Scanf("%d\n", &plots)
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	arrs := strings.Split(string(line), " ")
	arr := make([]int64, plots)
	for i, c := range arrs {
		arr[i], _ = strconv.ParseInt(c, 10, 64)
	}
	_, result := getMaxFloors(arr, arr, 0, plots-1)
	fmt.Println(result)
}

func getMaxFloors(arr, current []int64, start, end int) (int64, []int64) {
	if start == end {
		return arr[start], current
	}
	if start > end {
		return 0, current
	}
	minI, minV := start, arr[start]
	for i := start+1; i <= end; i++ {
		if arr[i] < minV {
			minI = i
			minV = arr[i]
		}
	}
	// fmt.Println(minI, minV, start, end)
	current1 := make([]int64, len(current))
	copy(current1, current)
	for i:=start;i<=minI;i++ {
		current1[i] = minV
	}
	r1, temp1:= getMaxFloors(arr, current1, minI+1, end)
	r1 += int64((minI - start + 1))*minV

	current2 := make([]int64, len(current))
	copy(current2, current)
	for i:=minI;i<=end;i++ {
		current2[i] = minV
	}
	r2, temp2 := getMaxFloors(arr, current2, start, minI-1)
	r2 += int64(end - minI + 1)*minV
	if r1 > r2 {
		// fmt.Println(r1, temp1)
		return r1, temp1
	}
	//fmt.Println(r2, temp2)
	return r2, temp2
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	maxh := int64(0)
	maxPos := 0
	for i, top := range a {
		cnt := top
		tmpMax := top
		for j := i; j >= 0; j-- {
			tmpMax = min(tmpMax, a[j])
			cnt+= tmpMax
		}
		tmpMax = top
		for j := i + 1; j < n; j++ {
			tmpMax = min(tmpMax, a[j])
			cnt+= tmpMax
		}
		if cnt > maxh {
			maxh = cnt
			maxPos = i
		}
	}

	ans := make([]int64, n)
	ans[maxPos] = a[maxPos]

	top := a[maxPos]
	tmpMax := top
	for j := maxPos; j >= 0; j-- {
		tmpMax = min(tmpMax, a[j])
		ans[j] = tmpMax
	}
	tmpMax = top
	for j := maxPos + 1; j < n; j++ {
		tmpMax = min(tmpMax, a[j])
		ans[j] = tmpMax

	}
	for i, v := range ans {
		if i > 0 {
			Fprint(out, " ")
		}
		Fprint(out, v)
	}
}

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

package main

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

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

	return n
}

func readData() (n, m, k int, connected [][]int, special []int) {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n = toInt(scanner.Bytes())

	scanner.Scan()
	m = toInt(scanner.Bytes())

	scanner.Scan()
	k = toInt(scanner.Bytes())

	special = make([]int, k)
	for i := range special {
		scanner.Scan()
		special[i] = toInt(scanner.Bytes())
	}
	// sort.Slice(special, func(i, j int) bool {
	// 	return special[i] < special[j]
	// })

	connected = make([][]int, 1+n)
	for i := int(0); i < m; i++ {
		scanner.Scan()
		x := toInt(scanner.Bytes())

		scanner.Scan()
		y := toInt(scanner.Bytes())

		connected[x] = append(connected[x], y)
		connected[y] = append(connected[y], x)
	}

	return
}

func solve(n, m, k int, connected [][]int, special []int) int {
	d, path := make([]int, n+1), make([]int, n+1)
	for i := range d {
		d[i] = m + 2
	}

	isSpecial := make([]bool, n+2)
	for _, n := range special {
		isSpecial[n] = true
	}

	q := []int{1}
	d[1] = 0

	for len(q) > 0 {
		p := q[len(q)-1]
		q = q[:len(q)-1]

		for _, n := range connected[p] {
			if d[n] > m {
				d[n] = d[p] + 1
				q = append(q, n)

				path[n] = p
			}
		}
	}

	res := 0

	c := 0
	last := -1
	for i := n; i > 0; i = path[i] {
		if isSpecial[i] {
			c++
			if last > 0 {
				t := d[i] + d[n] - d[last] + 1
				if t > res {
					res = t
				}
			}

			last = i
		}
	}

	if c < k {
		return d[n]
	}

	return res
}

func main() {
	fmt.Println(solve(readData()))
}

package main

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

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

	return n
}

func readData() []int {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n := toInt(scanner.Bytes())

	r := make([]int, n)
	for i := range r {
		scanner.Scan()
		r[i] = toInt(scanner.Bytes())
	}

	return r
}

func solve(heights []int) []int {
	L := len(heights)
	res, t := make([]int, L), make([]int, L)
	max := -1

	for i := 0; i < L; i++ {
		copy(t, heights)

		s := t[i]

		for j := i - 1; j >= 0; j-- {
			if t[j] > t[j+1] {
				t[j] = t[j+1]
			}
			s += t[j]
		}

		for j := i + 1; j < L; j++ {
			if t[j] > t[j-1] {
				t[j] = t[j-1]
			}
			s += t[j]
		}

		if s > max {
			max = s
			copy(res, t)
		}
	}

	return res
}

func main() {
	heights := readData()
	heights = solve(heights)

	for _, h := range heights {
		fmt.Printf("%d ", h)
	}
	fmt.Println()
}


Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

package main
import (
	"fmt"
	"sort"
)
func main() {
	var n int
	nt,cl,ch,mh :=0,0,1,1
	fmt.Scan(&n)
	f:=make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&f[i])
	}
	sort.Ints(f)
	for j:=0;j<n;j++ {
		if f[j]==cl {
			ch++
			if ch>mh {
				mh=ch
			}
		}else {
			cl = f[j]
			ch=1
			nt++
		}
	}
	fmt.Println(mh,nt)
}

package main

import "fmt"

func main() {
	var n, total int
	var maxheight = 1
	var bar, height []int
	fmt.Scanln(&n)
	total = n
	bar = make([]int, n)
	height = make([]int, 1001)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &bar[i])
	}
	for i := 0; i < len(bar); i++ {
		height[bar[i]]++
		if height[bar[i]] > 1 {
			total = total - 1
		}
		if maxheight < height[bar[i]] {
			maxheight = height[bar[i]]
		}
	}
	fmt.Printf("%d %d\n", maxheight, total)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	reader.ReadString('\n')
	barStr, _ := reader.ReadString('\n')
	barStr = strings.TrimSpace(barStr)
	barStrSl := strings.Split(barStr, " ")

	var bars []int
	for _, b := range barStrSl {
		bi, _ := strconv.Atoi(b)
		bars = append(bars, bi)
	}

	towers := make(map[int]int)

	for _, b := range bars {
		if _, ok := towers[b]; ok {
			towers[b]++
		} else {
			towers[b] = 1
		}
	}

	var highest int
	for _, val := range towers {
		if val > highest {
			highest = val
		}
	}
	fmt.Println(highest, len(towers))
}

package main

import (
	"fmt"
)

func main() {
	var (
		n, i, maxx, diff, maxh int32
		x, frek                []int32
	)

	fmt.Scan(&n)
	x = make([]int32, n, n)
	maxx = 0
	for i = 0; i < n; i++ {
		fmt.Scan(&x[i])
		if x[i] > maxx {
			maxx = x[i]
		}
	}

	//fmt.Println(x)

	frek = make([]int32, maxx+1, maxx+1)
	for i = 0; i < n; i++ {
		frek[x[i]]++
	}

	maxh, diff = 0, 0
	for i = 0; i <= maxx; i++ {
		if frek[i] > 0 {
			diff++
			if frek[i] > maxh {
				maxh = frek[i]
			}
		}
	}
	fmt.Printf("%d %d\n", maxh, diff)
}

package main

import "fmt"

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

func main() {
    var N,a int
    var x [1005]int
    fmt.Scan(&N)
    largest, cnt := 0, 0
    for i := 0; i < N; i++ {
        fmt.Scan(&a)
        if x[a] == 0 { cnt++ }
        x[a]++
        largest = max(largest,x[a])
    }
    fmt.Println(largest,cnt)
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	var v int
	max := 1
	a := make(map [int] int)
	for i:=0 ; i<n ; i++ {
		s.Scan()
		v, _ = strconv.Atoi(s.Text())
		w, ok := a[v]
		if ok {
			a[v] = w+1
			if max<w+1 {max=w+1}
		} else {
			a[v]=1
		}
	}

	fmt.Print(max)
	fmt.Print(" ")
	fmt.Println(len(a))

}

package main

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

func solve(n int, arr []int) {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] > arr[j] })
	count := make([]int, arr[0]+1)
	total := 0
	max := 0
	for i := range arr {
		count[arr[i]]++
	}

	for i := range count {
		if count[i] > 0 {
			total++
		}
		if count[i] > max {
			max = count[i]
		}
	}

	fmt.Fprintf(os.Stdout, "%d %d\n", max, total)
}

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

	arr := make([]int, n)
	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	solve(n, arr)
}

package main

import "fmt"

var height [1001]int

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

	v := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&v)
		height[v] += 1
	}

	max := 0
	for i := 0; i < len(height); i++ {
		if height[i] > max {
			max = height[i]
		}
	}

	num := n
	for i := 0; i < len(height); i++ {
		if height[i] != 0 {
			num = num - height[i] + 1
		}
	}

	fmt.Println(max, num)
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)

		mp[x]++
	}

	var mx int
	for _, vl := range mp {
		mx = max(mx, vl)
	}

	fmt.Println(mx, len(mp))
}

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

package main

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

/*
func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}
*/
func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	if N == 1 {
		fmt.Printf("%d %d", 1, 1)
	} else {
		var bars []int //nil slice
		for i := 0; i < N; i++ {
			var l int
			fmt.Scanf("%d", &l)
			bars = append(bars, l)
		}
		sort.Ints(bars)
		var towers []int
		max_ := math.MinInt16
		counter := 1
		for i := 0; i < N; i++ {
			if i == N-1 {
				if bars[i] != bars[i-1] {
					towers = append(towers, 0)
				} else {
					if counter >= max_ {
						max_ = counter
					}
					towers = append(towers, 0)
				}
				continue
			}
			if bars[i] == bars[i+1] {
				counter++
			} else {
				if counter >= max_ {
					max_ = counter
				}
				counter = 1
				towers = append(towers, 0)
			}
		}

		fmt.Printf("%d %d", max_, len(towers))
	}
}

// 37A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, jml, hi, max int
    fmt.Scan(&n)
    hi = 1
    max = 0
    c := make([]int, n)
    for i := range c {
        fmt.Scan(&c[i])
    }
    sort.Sort(sort.IntSlice(c))
    now := c[0]
    max = 1
    for k := 1; k < n; k++ {
        if c[k] == now {
            hi++
        } else {
            jml++
            hi = 1
            now = c[k]
        }
        if max < hi {
            max = hi
        }
    }
    fmt.Println(max, jml+1)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	reader.ReadString('\n')
	barStr, _ := reader.ReadString('\n')
	barStrSl := strings.Split(barStr, " ")

	var bars []int
	for _, b := range barStrSl {
		bi, _ := strconv.Atoi(b)
		bars = append(bars, bi)
	}

	towers := make(map[int]int)

	for _, b := range bars {
		if _, ok := towers[b]; ok {
			towers[b]++
		} else {
			towers[b] = 1
		}
	}

	var highest int
	for _, val := range towers {
		if val > highest {
			highest = val
		}
	}
	fmt.Println(highest, len(towers))
}

package main

import "fmt"

var height [1001]int

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

	v := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&v)
		height[v] += 1
	}

	max := 0
	for i := 0; i < len(height); i++ {
		if height[i] > max {
			max = height[i]
		}
	}

	num := n
	for i := 0; i < len(height); i++ {
		if height[i] == max {
			num = num - height[i] + 1
		}
	}

	fmt.Println(max, num)
}

package main

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

/*
func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}
*/
func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	var bars []int //nil slice
	for i := 0; i < N; i++ {
		var l int
		fmt.Scanf("%d", &l)
		bars = append(bars, l)
	}
	sort.Ints(bars)
	var towers []int
	max_ := math.MinInt16
	counter := 1
	for i := 0; i < N; i++ {
		if i == N-1 {
			if bars[i] != bars[i-1] {
				towers = append(towers, 0)
			}
			continue
		}
		if bars[i] == bars[i+1] {
			counter++
		} else {
			if counter >= max_ {
				max_ = counter
			}
			counter = 1
			towers = append(towers, 0)
		}
	}

	fmt.Printf("%d %d", max_, len(towers))
}

package main

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

func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var bars []int //nil slice
	for i := 0; i < N; i++ {
		var l int
		fmt.Scanf("%d ", &l)
		bars = append(bars, l)
	}

	sort.Ints(bars)
	var towers []int
	max_ := math.MinInt16
	counter := 1
	for i := 0; i < N; i++ {
		if i == N-1 {
			if bars[i] != bars[i-1] {
				towers = append(towers, 0)
			}
			continue
		}
		if bars[i] == bars[i+1] {
			counter++
		} else {
			if counter >= max_ {
				max_ = counter
			}
			counter = 1
			towers = append(towers, 0)
		}
	}

	fmt.Printf("%d %d", max_, len(towers))
}

package main

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

func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var bars []int //nil slice
	for i := 0; i < N; i++ {
		var l int
		fmt.Scanf("%d", &l)
		bars = append(bars, l)
	}

	sort.Slice(bars, func (i, j int) bool { return bars[i] < bars[j] })
	var towers []int
	max_ := math.MinInt16
	counter := 1
	for i := 0; i < N; i++ {
		if i == N-1 {
			if bars[i] != bars[i-1] {
				towers = append(towers, 0)
			}
			continue
		}
		if bars[i] == bars[i+1] {
			counter++
		} else {
			if counter >= max_ {
				max_ = counter
			}
			counter = 1
			towers = append(towers, 0)
		}
	}

	fmt.Printf("%d %d", max_, len(towers))
}

package main

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

func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var bars []int //nil slice
	for i := 0; i < N; i++ {
		var l int
		fmt.Scanf("%d", &l)
		bars = append(bars, l)
	}

	sort.Slice(bars, func (i, j int) bool { return bars[i] < bars[j] })
	var towers []int
	max_ := math.MinInt16
	counter := 1
		fmt.Println(bars)
	for i := 0; i < N; i++ {
		if i == N-1 {
			if bars[i] != bars[i-1] {
				towers = append(towers, 0)
			}
			continue
		}
		if bars[i] == bars[i+1] {
			counter++
		} else {
			if counter >= max_ {
				max_ = counter
			}
			counter = 1
			towers = append(towers, 0)
		}
	}

	fmt.Printf("%d %d", max_, len(towers))
}

package main

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

func readLine(reader *bufio.Reader) string {
	line, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}
	return strings.TrimRight(string(line), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	var bars []int //nil slice
	for i := 0; i < N; i++ {
		var l int
		fmt.Scanf("%d", &l)
		bars = append(bars, l)
	}

	sort.Ints(bars)
	var towers []int
	max_ := math.MinInt16
	counter := 1
	for i := 0; i < N; i++ {
		if i == N-1 {
			if bars[i] != bars[i-1] {
				towers = append(towers, 0)
			}
			continue
		}
		if bars[i] == bars[i+1] {
			counter++
		} else {
			if counter >= max_ {
				max_ = counter
			}
			counter = 1
			towers = append(towers, 0)
		}
	}

	fmt.Printf("%d %d", max_, len(towers))
}

// 37A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, jml, hi int
    fmt.Scan(&n)
    hi = 1
    c := make([]int, n)
    for i := range c {
        fmt.Scan(&c[i])
    }
    sort.Sort(sort.IntSlice(c))
    for k := 0; k < n-1; k++ {
        if c[k] == c[k+1] {
            hi++
            jml++
            k++
        } else {
            jml++
        }
    }
    fmt.Println(hi, jml+1)
}

// 37A-mic
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, jml, hi, max int
	fmt.Scan(&n)
	hi = 1
	max = 0
	c := make([]int, n)
	for i := range c {
		fmt.Scan(&c[i])
	}
	sort.Sort(sort.IntSlice(c))
	now := c[0]
	for k := 1; k < n; k++ {
		if c[k] == now {
			hi++
		} else {
			jml++
			hi = 1
			now = c[k]
		}
		if max < hi {
			max = hi
		}
	}
	fmt.Println(max, jml+1)
}

// 37A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, jml, hi, m, max int
    fmt.Scan(&n)
    hi = 1
    c := make([]int, n)
    for i := range c {
        fmt.Scan(&c[i])
    }
    sort.Sort(sort.IntSlice(c))
    for k := 0; k <= n-1; k++ {
        if k == n-1 {
            jml++
            break
        }
        if c[k] == c[k+1] {
            if c[k] != m {
                max = hi
                hi = 1
            }
            hi++
            jml++
            m = c[k]
            k++
        } else {
            jml++
        }
        if max < hi {
            max = hi
        }
    }
    fmt.Println(hi, jml)
}

// 37A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, jml, hi int
    fmt.Scan(&n)
    hi = 1
    c := make([]int, n)
    for i := range c {
        fmt.Scan(&c[i])
    }
    sort.Sort(sort.IntSlice(c))
    for k := 0; k <= n-1; k++ {
        if k == n-1 {
            jml++
            break
        }
        if c[k] == c[k+1] {
            hi++
            jml++
            k++
        } else {
            jml++
        }
    }
    fmt.Println(hi, jml)
}


Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t tickets, each of which was lucky.When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.What maximum number of tickets could Vasya get after that?

The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.

Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.

package main

import (
    "fmt"
)

func main(){
    n := 0
    fmt.Scanf("%d\n", &n)
    mods := make([]int, 4)
    aux := 0
    for i:=0; i <n; i++{
        fmt.Scanf("%d", &aux)
        mods[aux%3] ++
    }
    x := mods[1]
    if x > mods[2]{
        x = mods[2]
    }
    fmt.Println(int(mods[0]/2) + x)
}


Students of Winter Informatics School are going to live in a set of houses connected by underground passages. Teachers are also going to live in some of these houses, but they can not be accommodated randomly. For safety reasons, the following must hold:  All passages between two houses will be closed, if there are no teachers in both of them. All other passages will stay open.  It should be possible to travel between any two houses using the underground passages that are open.  Teachers should not live in houses, directly connected by a passage. Please help the organizers to choose the houses where teachers will live to satisfy the safety requirements or determine that it is impossible.

The first input line contains a single integer $$$t$$$ — the number of test cases ($$$1 \le t \le 10^5$$$).  Each test case starts with two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$0 \le m \le 3 \cdot 10^5$$$) — the number of houses and the number of passages. Then $$$m$$$ lines follow, each of them contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$), describing a passage between the houses $$$u$$$ and $$$v$$$. It is guaranteed that there are no two passages connecting the same pair of houses. The sum of values $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$, and the sum of values $$$m$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, if there is no way to choose the desired set of houses, output "NO". Otherwise, output "YES", then the total number of houses chosen, and then the indices of the chosen houses in arbitrary order.

NoteThe picture below shows the second example test.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1470D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return 0
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

o:
	for T := r(); T > 0; T-- {
		n := r()
		g := make([][]int, n)
		for m := r(); m > 0; m-- {
			v, w := r()-1, r()-1
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		color := make([]int8, n)
		var f func(int)
		f = func(v int) {
			if color[v] == 1 {
				todo := []int{}
				for _, w := range g[v] {
					if color[w] == 0 {
						color[w] = 2
						todo = append(todo, w)
					}
				}
				for _, w := range todo {
					f(w)
				}
			} else {
				for _, w := range g[v] {
					if color[w] == 0 {
						color[w] = 1
						f(w)
					}
				}
			}
		}
		color[0] = 1
		f(0)
		ans := []interface{}{}
		for i, c := range color {
			if c == 0 {
				Fprintln(out, "NO")
				continue o
			}
			if c == 1 {
				ans = append(ans, i+1)
			}
		}
		Fprintln(out, "YES")
		Fprintln(out, len(ans))
		Fprintln(out, ans...)
	}
}

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

package main

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

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

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var n, m, u, v int
	fmt.Fscan(in, &n, &m)

	adj := make([][]int, n+1)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &u, &v)
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	mark := make([]int, n+1)
	mark[1] = 1
	q := []int{1}

	for len(q) > 0 {
		c := q[0]
		q = q[1:]

		if mark[c] == 1 {
			for _, d := range adj[c] {
				if mark[d] != 2 {
					mark[d] = 2
					q = append(q, d)
				}
			}
		} else {
			for _, d := range adj[c] {
				if mark[d] == 0 {
					mark[d] = 1
					q = append(q, d)
				}
			}
		}
	}

	ok := true
	res := []int{}
	for i := 1; i <= n; i++ {
		if mark[i] == 0 {
			ok = false
			break
		}
		if mark[i] == 1 {
			res = append(res, i)
		}
	}

	if !ok {
		fmt.Fprintln(out, "NO")
	} else {
		fmt.Fprintf(out, "YES\n%d\n", len(res))
		for _, i := range res {
			fmt.Fprintf(out, "%d ", i)
		}
		fmt.Fprintf(out, "\n")
	}
}


There are n stone quarries in Petrograd.Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik».

The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.

Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.

package main

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

var scanner *bufio.Scanner

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

func fillParity(x int64, parity []int64) {
  y := x / 2
  pos := 0
  for mask := int64(2); mask <= 2 * x; mask *= 2 {
    z := x % mask
    if z >= mask / 2 {
      y += z + 1 - mask / 2
    }
    parity[pos] ^= y % 2
    y = 0
    pos++
  }
}

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

  n := getI()
  parity := make([]int64, 71)

  for i := 0; i < n; i++ {
    x, m := getI64(), getI64()
    fillParity(x + m - 1, parity)
    fillParity(x - 1, parity)
  }
  result := "bolik"
  for _, b := range parity {
    if b == 1 {
      result = "tolik"
      break
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}