Let's say you are standing on the $$$XY$$$-plane at point $$$(0, 0)$$$ and you want to reach point $$$(n, n)$$$.You can move only in two directions:   to the right, i. e. horizontally and in the direction that increase your $$$x$$$ coordinate,  or up, i. e. vertically and in the direction that increase your $$$y$$$ coordinate. In other words, your path will have the following structure:   initially, you choose to go to the right or up;  then you go some positive integer distance in the chosen direction (distances can be chosen independently);  after that you change your direction (from right to up, or from up to right) and repeat the process. You don't like to change your direction too much, so you will make no more than $$$n - 1$$$ direction changes.As a result, your path will be a polygonal chain from $$$(0, 0)$$$ to $$$(n, n)$$$, consisting of at most $$$n$$$ line segments where each segment has positive integer length and vertical and horizontal segments alternate.Not all paths are equal. You have $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ where $$$c_i$$$ is the cost of the $$$i$$$-th segment.Using these costs we can define the cost of the path as the sum of lengths of the segments of this path multiplied by their cost, i. e. if the path consists of $$$k$$$ segments ($$$k \le n$$$), then the cost of the path is equal to $$$\sum\limits_{i=1}^{k}{c_i \cdot length_i}$$$ (segments are numbered from $$$1$$$ to $$$k$$$ in the order they are in the path).Find the path of the minimum cost and print its cost.

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^9$$$) — the costs of each segment. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$10^5$$$.

For each test case, print the minimum possible cost of the path from $$$(0, 0)$$$ to $$$(n, n)$$$ consisting of at most $$$n$$$ alternating segments.

NoteIn the first test case, to reach $$$(2, 2)$$$ you need to make at least one turn, so your path will consist of exactly $$$2$$$ segments: one horizontal of length $$$2$$$ and one vertical of length $$$2$$$. The cost of the path will be equal to $$$2 \cdot c_1 + 2 \cdot c_2 = 26 + 176 = 202$$$.In the second test case, one of the optimal paths consists of $$$3$$$ segments: the first segment of length $$$1$$$, the second segment of length $$$3$$$ and the third segment of length $$$2$$$.The cost of the path is $$$1 \cdot 2 + 3 \cdot 3 + 2 \cdot 1 = 13$$$.In the third test case, one of the optimal paths consists of $$$4$$$ segments: the first segment of length $$$1$$$, the second one — $$$1$$$, the third one — $$$4$$$, the fourth one — $$$4$$$. The cost of the path is $$$1 \cdot 4 + 1 \cdot 3 + 4 \cdot 2 + 4 \cdot 1 = 19$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n int64
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}

		fmt.Println(PathWithMinCost(n, a))
	}

}

func PathWithMinCost(n int64, costs []int64) int64 {

	var countOdd int64 = 1
	sumOdd := costs[0]
	var countEven int64 = 1
	sumEven := costs[1]
	minOdd := costs[0]
	minEven := costs[1]

	minCost := n * (minEven + minOdd)

	for i := 2; i < len(costs); i++ {
		if i % 2 == 0 {
			countOdd++
			sumOdd += costs[i]
			if minOdd > costs[i] {
				minOdd = costs[i]
			}
		} else {
			countEven++
			sumEven += costs[i]
			if minEven > costs[i] {
				minEven = costs[i]
			}
		}

		cost := sumOdd + minOdd * (n - countOdd) + sumEven + minEven * (n - countEven)
		if minCost > cost {
			minCost = cost
		}
	}

	return minCost
}

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		m := a[:2]
		s := []int64{a[0], a[1]}
		c := []int64{1, 1}
		ans := (a[0] + a[1]) * n
		for i, v := range a[2:] {
			i &= 1
			s[i] += v
			if v < m[i] {
				m[i] = v
			}
			c[i]++
			if r := s[0]+m[0]*(n-c[0])+s[1]+m[1]*(n-c[1]); r < ans {
				ans = r
			}
		}
		Println(ans)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		mi0, mi1 := a[0], a[1]
		ans := (mi0 + mi1) * int64(n)
		if n == 2 {
			Fprintln(out, ans)
			return
		}
		c0, c1 := 1, 1
		s0, s1 := mi0, mi1
		for i := 2; i < n; i++ {
			if i&1 == 0 {
				s0 += a[i]
				mi0 = min(mi0, a[i])
				c0++
			} else {
				s1 += a[i]
				mi1 = min(mi1, a[i])
				c1++
			}
			res := (s0 - mi0) + mi0*int64(n+1-c0)
			res += (s1 - mi1) + mi1*int64(n+1-c1)
			ans = min(ans, res)
		}

		Fprintln(out, ans)
	}

	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) }
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

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

var ret *big.Int

func isPrime(x int) bool {
	for i := 2; i < x; i++ {
		if x % i == 0 {
			return false
		}
	}
	return true
}

func dfs(dep, maxDep, n int, a, primeArr []int32, used []bool) {
	if dep == maxDep {
		cur := big.NewInt(1)
		for i := 0; i < n; i++ {
			curFlag := false
			for j := 0; j < maxDep; j++ {
				if used[j] && a[i] % primeArr[j] == 0 {
					curFlag = true
				}
			}
			if !curFlag {
				return
			}
		}
		for i := 0; i < maxDep; i++ {
			if used[i] {
				cur.Mul(cur, big.NewInt(int64(primeArr[i])))
			}
		}
		//fmt.Println(cur)
		if ret.Cmp(big.NewInt(0)) == 0 || -1 == cur.Cmp(ret) {
			ret = cur
		}
		return
	}
	used[dep] = true
	dfs(dep + 1, maxDep, n, a, primeArr, used)
	used[dep] = false
	dfs(dep + 1, maxDep, n, a, primeArr, used)
}

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

func main() {
	input()
}

func input() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	var T int
	T = nextNum()
	for i := 0; i < T; i++ {
		var n int
		n = nextNum()
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = nextNum()
		}
		fmt.Println(answer(n, a))
	}
}

func answer(n int, a []int) int64 {
	ans := int64(n) * int64(a[0] + a[1])
	min0 := a[0]
	min1 := a[1]
	num0 := n
	num1 := n
	cur := ans
	for i := 2; i < n; i++ {
		if i % 2 == 0 {
			if a[i] >= min0 {
				cur = cur - int64(min0) + int64(a[i])
				num0--
			} else {
				cur = cur - int64(min0) * int64(num0 - 1) + int64(num0 - 1) * int64(a[i])
				min0 = a[i]
				num0--
			}
		} else {
			if a[i] >= min1 {
				cur = cur - int64(min1) + int64(a[i])
				num1--
			} else {
				cur = cur - int64(min1) * int64(num1 - 1) + int64(num1 - 1) * int64(a[i])
				min1 = a[i]
				num1--
			}
		}
		ans = min(ans, cur)
	}
	return ans
}

func min(x, y int64) int64 {
	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"
)

var in *bufio.Reader

func solve() {
	var n int64
	fmt.Fscan(in, &n)

	c := make([]int, n)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(in, &c[i])
	}

	evenMin, oddMin := c[0], c[1]
	evenAcc, oddAcc := int64(evenMin), int64(oddMin)
	evenSum, oddSum := int64(evenMin)*n, int64(oddMin)*n
	result := evenSum + oddSum
	for i := int64(2); i < n; i++ {
		if i%2 == 0 {
			evenAcc += int64(c[i])
			if c[i] < evenMin {
				evenMin = c[i]
			}
			evenSum = evenAcc + (n-(i/2+1))*int64(evenMin)
		} else {
			oddAcc += int64(c[i])
			if c[i] < oddMin {
				oddMin = c[i]
			}
			oddSum = oddAcc + (n-(i/2+1))*int64(oddMin)
		}
		cur := evenSum + oddSum
		if cur < result {
			result = cur
		}
	}
	fmt.Println(result)
}

func main() {
	in = bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		solve()
	}
}

/*
* Filename: C/main.go
* Timestamp: 07-06-2021 14:24:44
* Author: Fadhil Musaad
 */

package main

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

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

func scan(a ...interface{})    { fmt.Fscan(reader, a...) }
func scanln(a ...interface{})  { fmt.Fscanln(reader, a...) }
func print(a ...interface{})   { fmt.Fprint(writer, a...) }
func println(a ...interface{}) { fmt.Fprintln(writer, a...) }

func solve(_r io.Reader, _w io.Writer) {
	reader = bufio.NewReader(_r)
	writer = bufio.NewWriter(_w)
	defer writer.Flush()

	var t int
	scanln(&t)
	for ; t > 0; t-- {
		var n int64
		scanln(&n)
		var odd, even int64 = 1000000005, 1000000005
		sum := int64(0)
		x, y := int64(0), int64(0)

		min := func(a, b int64) int64 {
			if a < b {
				return a
			}
			return b
		}
		ans := int64(1000000000000000000)
		for i := int64(0); i < n; i++ {
			var a int64
			scan(&a)
			if i%2 == 1 {
				x++
				odd = min(odd, a)
			} else {
				y++
				even = min(even, a)
			}
			sum += a
			cur := sum + odd*(n-x) + even*(n-y)
			ans = min(ans, cur)
		}
		scanln()
		println(ans)
	}
}

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

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		C := readNNums(reader, n)
		res := solve(n, C)
		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
}

func solve(n int, C []int) int64 {
	/**
	分成两部分偶数和奇数部分；
	偶数部分用于垂直移动，奇数部分用于水平移动；
	那么其中个部分的最小值应该移动最多n - m + 1, 其他的部分移动m-1
	*/
	x, y := C[0], C[1]
	N := int64(n)
	best := N * (int64(x) + int64(y))
	sh := int64(x)
	sv := int64(y)
	for i := 2; i < n; {
		x = min(x, C[i])
		sh += int64(C[i])
		// if take i segs, and i is horizontal
		m := i/2 + 1
		// horiontal part
		tmp := int64(n-m+1)*int64(x) + sh - int64(x)
		m--
		// vertical part
		tmp += int64(n-m+1)*int64(y) + sv - int64(y)
		best = min2(best, tmp)
		i++
		if i < n {
			y = min(y, C[i])
			sv += int64(C[i])
			// if i == 3, then m = 2
			m = i/2 + 1

			tmp = int64(n-m+1)*int64(x) + sh - int64(x)
			tmp += int64(n-m+1)*int64(y) + sv - int64(y)
			best = min2(best, tmp)
			i++
		}
	}
	return best
}

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

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

package main

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

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

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

	// single test case
	var tt int
	Fscan(in, &tt)

	for tt > 0 {
		tt--

		var nn int64
		Fscan(in, &nn)

		mn := []int64{1e9, 1e9}
		rem := []int64{int64(nn), int64(nn)}
		sum := int64(0)
		ans := int64(1e18)

		a := make([]int64, nn)
		for i := int64(0); i < nn; i++ {
			Fscan(in, &a[i])
		}

		for k := range a {
			mn[k%2] = min(mn[k%2], a[k])
			rem[k%2]--
			sum += a[k]
			if k > 0 {
				cur := sum + rem[0]*mn[0] + rem[1]*mn[1]
				ans = min(ans, cur)
			}
		}

		Fprint(out, ans, "\n")
	}

	// 입력 에러 방지
	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("읽지않은 데이터 발견：\n" + _s)
	}
}

// LETYLETYLETY
func main() { CF106c(os.Stdin, os.Stdout) }

// YTELYTELYTEL

package main

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

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

func solve() {
	var n int64
	scan(&n)
	a := make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

	var ans int64 = math.MaxInt64
	var cntEven, cntOdd int64 = 1, 0
	var sumEven, sumOdd int64 = a[0], 0
	var minEven, minOdd int64 = a[0], 1e9 + 1

	f := func() int64 {
		reven := (sumEven - minEven) + minEven*(n-(cntEven-1))
		rodd := (sumOdd - minOdd) + minOdd*(n-(cntOdd-1))
		return reven + rodd
	}

	for i := int64(1); i < n; i++ {
		if i%2 == 0 {
			sumEven += a[i]
			if minEven > a[i] {
				minEven = a[i]
			}
			cntEven++
		} else {
			sumOdd += a[i]
			if minOdd > a[i] {
				minOdd = a[i]
			}
			cntOdd++
		}

		res := f()
		if res < ans {
			ans = res
		}
	}

	printf("%v\n", ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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
		var ans ,v int64
		Fscan(in, &n)
		a := make([][]int64, 2)
		for i := range a {
			a[i] = make([]int64,0, n/2)
		}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			a[i&1] = append(a[i&1], v)
		}

		for _, a := range a {
			mi := int64(1e18)
			s := int64(0)
			for i, v := range a {
				mi = min(mi, s+int64(n-i)*v)
				s+=v
			}
			ans+=mi
		}

		Fprintln(out, ans)
	}

	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) }
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}


You are both a shop keeper and a shop assistant at a small nearby shop. You have $$$n$$$ goods, the $$$i$$$-th good costs $$$a_i$$$ coins.You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all $$$n$$$ goods you have.However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all $$$n$$$ goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.So you need to find the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 100)$$$ — the number of goods. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^7$$$), where $$$a_i$$$ is the price of the $$$i$$$-th good.

For each query, print the answer for it — the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne()
	}
}

func solveOne() {
	n := readInt()
	sum := int64(0)
	for i := 0; i < n; i++ {
		sum += readInt64()
	}
	d := int64(0)
	if sum%int64(n) > 0 {
		d = int64(1)
	}
	printInt64(sum/int64(n) + d)
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			sum += a
		}
		fmt.Printf("%.0f\n", math.Ceil(float64(sum)/float64(n)))
	}
}

package main

import "fmt"

func main() {
	var q int
	fmt.Scan(&q)
	for ; q > 0; q-- {
		var n, a, sum int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a)
			sum += a
		}
		fmt.Println((sum + n - 1) / n)
	}
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var q int
	fmt.Fscan(buf, &q)
	for ; q > 0; q-- {
		var n, a, sum int
		fmt.Fscan(buf, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(buf, &a)
			sum += a
		}
		fmt.Println((sum + n - 1) / n)
	}
}

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var q int

func main() {
	defer writer.Flush()

	Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		Scanf("%d\n", &n)
		sum := int64(0)
		for j := 0; j < n; j++ {
			var ai int64
			Scanf("%d", &ai)
			sum += ai
		}
		Scanf("\n")
		div := sum / int64(n)
		if sum%int64(n) != 0 {
			div++
		}
		Printf("%d\n", div)
	}
}

// https://codeforces.com/problemset/problem/1234/A

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		var sum int
		for j := 0; j < n; j++ {
			var temp int
			if j == n-1 {
				fmt.Fscanf(in, "%d\n", &temp)
			} else {
				fmt.Fscanf(in, "%d", &temp)
			}
			sum += temp
		}
		ans := sum / n
		if sum%n != 0 {
			fmt.Fprintln(out, ans+1)
		} else {
			fmt.Fprintln(out, ans)
		}
	}

}

package main

import "fmt"

func ceil(a, b int) int {
	return (a + b - 1) / b
}

func main() {
	var N int
	fmt.Scan(&N)
	q := make([][]int, N)
	a := make([]int, N)
	for i := range q {
		var t, v int
		fmt.Scan(&t)
		q[i] = make([]int, t)
		for j := 0; j < t; j++ {
			fmt.Scan(&q[i][j])
			v += q[i][j]
		}
		a[i] = ceil(v, len(q[i]))
	}
	for i := 0; i < len(a); i++ {
		fmt.Println(a[i])
	}
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

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

func main() {
	for q := ReadInt(); q > 0; q-- {
		n := ReadInt()
		a := ReadIntSlice(n)
		sum := 0
		for _, val := range a {
			sum += val
		}
		ans := (sum + n - 1) / n
		fmt.Println(ans)
	}
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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
}

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

// PrintIntsLine returns integers string delimited by a space.
func PrintlnInts(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)
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

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

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

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

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

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

	return res
}

/*********** Arithmetic ***********/

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

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

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		n := ReadInt()
		A := ReadIntSlice(n)

		sum := Sum(A...)
		fmt.Println((sum + (n - 1)) / n)
	}
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

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

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

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

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

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

	return res
}

/*********** Arithmetic ***********/

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

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

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int

func main() {
	q = ReadInt()
	for i := 0; i < q; i++ {
		n := ReadInt()
		A := ReadIntSlice(n)

		sum := Sum(A...)
		fmt.Println(Kiriage(sum, n))
	}
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

import (
	"fmt"
	"os"
)

func main() {
	_, err := os.Stat("in.txt")
	if err == nil {
		os.Stdin, err = os.OpenFile("in.txt", os.O_RDONLY, 0666)
	}

	var n, m, a, s int

	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&m)
		s = 0
		for j:=0; j<m; j++ {
			fmt.Scan(&a)
			s+=a
		}
		if (s%m==0) {
			fmt.Println(s/m)
		} else {
			fmt.Println(s/m+1)
		}

	}
}

package main

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

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

func f(in io.Reader, out io.Writer) {
	s := bufio.NewScanner(in)
	q := parse(read(s))

	for i := 0; i < int(q); i += 1 {
		n := float64(parse(read(s)))
		r := 0.0
		for _, item := range strings.Split(read(s), " ") {
			r += float64(parse(item))
		}
		fmt.Fprintln(out, int(math.Ceil(r / n)))
	}
}

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

func parse(s string) int {
	r, _ := strconv.ParseInt(s, 10, 64)
	return int(r)
}

package main

import "fmt"

func main() {
	var a int
	fmt.Scanf("%d\n", &a)
	// fmt.Println(a)
	for p := a; p > 0; p-- {
		n := 0
		fmt.Scanf("%d\n", &n)
		// fmt.Println(n)
		ans := 0.0
		for j := 0; j < n; j++ {
			tmp := 0
			if j == n-1 {
				fmt.Scanf("%d\n", &tmp)
			} else {
				fmt.Scanf("%d", &tmp)
			}
			ans += float64(tmp)
		}
		fmt.Println(int((ans + float64(n) - 1.0) / float64(n)))
	}
}

package main

import "fmt"

func main() {
	var size int
	var arrSize int
	fmt.Scanln(&size)
	for i := 0; i < size; i++ {
		fmt.Scanln(&arrSize)
		sum := 0
		var num int
		for j := 0; j < arrSize; j++ {
			fmt.Scanf("%d", &num)
			sum = num + sum
		}
		fmt.Scanln()
		result := sum / arrSize
		if sum % arrSize != 0 {
			result++
		}
		fmt.Println(result)
	}
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

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

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

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	q := readi()
	for i := 0; i < q; i++ {
		n := readi()
		a := make([]int, n)
		for i := range a {
			a[i] = readi()
		}
		println(solve(n, a))
	}
}

func solve(n int, a []int) int {
	sum := 0
	for _, v := range a {
		sum += v
	}
	res := sum / n
	if sum%n != 0 {
		res++
	}
	return res
}

package main

import (
	"fmt"
)

//noinspection GoUnhandledErrorResult
func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	for qq := 0; qq < q; qq += 1 {
		var n, t int
		s := 0
		fmt.Scanf("%d\n", &n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &t)
			s += t
		}
		fmt.Scanf("\n")
		if s%n == 0 {
			fmt.Println(s / n)
		} else {
			fmt.Println(s/n + 1)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var T int
	_, _ = fmt.Scan(&T)
	for T > 0 {
		var n int
		var x, sum float64
		_, _ = fmt.Scan(&n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Scan(&x)
			sum += x
		}
		fmt.Println(int64(math.Ceil(sum / float64(n))))
		T--
	}
}

package main

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

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

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

	for ; q > 0; q-- {
		var n, t, s int64
		fmt.Fscanf(reader, "%d\n", &n)

		for i := int64(0); i < n; i++ {
			if i == n-1 {
				fmt.Fscanf(reader, "%d\n", &t)
			} else {
				fmt.Fscanf(reader, "%d", &t)
			}

			s += t
		}

		if s%n == 0 {
			fmt.Printf("%d\n", s/n)
		} else {
			fmt.Printf("%d\n", s/n+1)
		}
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1234/problem/A

package main

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

func ceilDiv(sum int, n int) int {
	return (sum + n - 1) / n
}

func Solve(n int, a []int) int {
	sum := 0
	for _, elem := range a {
		sum += elem
	}
	return ceilDiv(sum, n)
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", Solve(n, a))
	}
}

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			sum += a
		}
		fmt.Printf("%.0f", math.Ceil(float64(sum)/float64(n)))
	}
}

// https://codeforces.com/problemset/problem/1234/A

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		var sum int
		for j := 0; j < n; j++ {
			var temp int
			if j == n-1 {
				fmt.Fscanf(in, "%d\n", &temp)
			} else {
				fmt.Fscanf(in, "%d", &temp)
			}
			sum += temp
		}
		ans := sum / n
		if sum%n != 0 {
			check := ans * n
			fmt.Fprintln(out, check-ans)
		} else {
			fmt.Fprintln(out, ans)
		}
	}

}

package main

import "fmt"

func main() {
	var size int
	fmt.Scanln(&size)
	for i := 0; i < size; i++ {
		var arrSize int
		fmt.Scanf("%d", &arrSize)
		sum := 0
		for j := 0; j < arrSize; j++ {
			var num int
			fmt.Scanf("%d", &num)
			sum += num
		}
		result := sum / arrSize
		if sum % arrSize != 0 {
			result++
		}
		fmt.Println(result)
	}
}

package main

import (
	"fmt"
	"os"
)

//noinspection GoUnhandledErrorResult
//
func main() {
	//in, _ := os.OpenFile("data/in.txt", os.O_RDONLY, 0)
	//defer in.Close()
	//out, _ := os.OpenFile("data/out.txt", os.O_WRONLY, 0)
	//defer out.Close()

	in := os.Stdin
	out := os.Stdout

	var q int
	fmt.Fscanf(in, "%d\n", &q)
	for qq := 0; qq < q; qq += 1 {
		var n, t int
		s := 0
		fmt.Fscanf(in, "%d\n", &n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &t)
		}
		fmt.Fscanf(in, "\n")
		if s%n == 0 {
			fmt.Fprintln(out, s/n)
		} else {
			fmt.Fprintln(out, s/n+1)
		}
	}
}

package main

import (
	"fmt"
)

//noinspection GoUnhandledErrorResult
func main() {
	var q int
	fmt.Scanf("%d\n", &q)
	for qq := 0; qq < q; qq += 1 {
		var n, t int
		s := 0
		fmt.Scanf("%d\n", &n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &t)
		}
		fmt.Scanf("\n")
		if s%n == 0 {
			fmt.Println(s / n)
		} else {
			fmt.Println(s/n + 1)
		}
	}
}

package main

import (
	"fmt"
	"os"
)

//noinspection GoUnhandledErrorResult
//
func main() {
	//in, _ := os.OpenFile("data/in.txt", os.O_RDONLY, 0)
	//defer in.Close()
	//out, _ := os.OpenFile("data/out.txt", os.O_WRONLY, 0)
	//defer out.Close()

	in := os.Stdin
	out := os.Stdout

	var q int
	fmt.Fscanf(in, "%d\n", &q)
	defer println(q)
	for qq := 0; qq < q; qq += 1 {
		var n, t int
		s := 0
		fmt.Fscanf(in, "%d\n", &n)
		defer println(n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &t)
			defer println(t)
		}
		fmt.Fscanf(in, "\n")
		if s%n == 0 {
			fmt.Fprintln(out, s/n)
		} else {
			fmt.Fprintln(out, s/n+1)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var T int
	_, _ = fmt.Scan(&T)
	for T > 0 {
		var n int
		var x, sum float64
		_, _ = fmt.Scan(&n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Scan(&x)
			sum += x
		}
		fmt.Println(math.Ceil(sum / float64(n)))
		T--
	}
}


You are given an array $$$a_1, a_2, \ldots, a_n$$$.In one operation you can choose two elements $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$) and decrease each of them by one.You need to check whether it is possible to make all the elements equal to zero or not.

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

Print "YES" if it is possible to make all elements zero, otherwise print "NO".

NoteIn the first example, you can make all elements equal to zero in $$$3$$$ operations:   Decrease $$$a_1$$$ and $$$a_2$$$,  Decrease $$$a_3$$$ and $$$a_4$$$,  Decrease $$$a_3$$$ and $$$a_4$$$ In the second example, one can show that it is impossible to make all elements equal to zero.

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n := readInt()
	max := int64(0)
	sum := int64(0)
	for i := 0; i < n; i++ {
		v := int64(readInt())
		sum += v
		if v > max {
			max = v
		}
	}

	if sum%2 == 0 && max <= (sum-max) {
		println("YES")
	} else {
		println("NO")
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
	} else {
		f = os.Stdin
	}
	defer f.Close()

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
}

func println(s string) {
	print(s)
	print("\n")
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1201/B

package main

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

func Solve(n int, a []int64) string {
	var sum int64
	var maxElement int64
	for i := 0; i < n; i++ {
		sum += a[i]
		if a[i] > maxElement {
			maxElement = a[i]
		}
	}
	if sum%2 == 0 && maxElement <= (sum-maxElement) {
		return "YES"
	}
	return "NO"
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n := readInt()
	ok := 0
	for i := 0; i < n; i++ {
		ok = (ok + readInt()) % 2
	}

	if ok == 0 {
		println("YES")
	} else {
		println("NO")
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
	} else {
		f = os.Stdin
	}
	defer f.Close()

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
}

func println(s string) {
	print(s)
	print("\n")
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1201/B

package main

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

func Solve(n int, a []int) string {
	sum := 0
	maxElement := 0
	for i := 0; i < n; i++ {
		sum += a[i]
		if a[i] > maxElement {
			maxElement = a[i]
		}
	}
	if sum%2 == 0 && maxElement <= (sum-maxElement) {
		return "YES"
	}
	return "NO"
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}


Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions:  The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.  No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n).  Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.

A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters.

In a single line print the required string. If there isn't such string, print "-1" (without the quotes).

package main

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

func main() {
	var n,k int
	out := bufio.NewWriter(os.Stdout)
	var x rune
	fmt.Scan(&n,&k)
	if n<k || (k==1 && n!=1) {
		fmt.Println("-1")
	} else {
		for ;n>k && n>2;n-=2 {
			out.WriteString("ab")
			//fmt.Print("ab")
		}
		if n==1 || n!=k {
			out.WriteString("a")
			//fmt.Print("a")
		} else {
			out.WriteString("ab")
			//fmt.Print("ab")
		}
		for i:=2;i<k;i++ {
			x='a'+ rune(i)
			out.WriteString(string(x))
			//fmt.Print(string(x))
		}
		out.Flush()
	}
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n,k int
    fmt.Scan(&n,&k)
    if (n == 1) && (k == 1) {
        fmt.Println("a")
    } else if (n < k) || (k > 26) || (k == 1) {
        fmt.Println(-1)
    } else {
        k -= 2
        c, t := 'a', n-k
        for i := 0; i < t; i++ {
            writer.WriteRune(c)
            if c == 'a' { c = 'b' } else { c = 'a' }
        }
        c = 'c'
        for i := 0; i < k; i++ {
            writer.WriteRune(c)
            c++
        }
        writer.WriteRune('\n')
        writer.Flush()
    }
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)            // membuat variabel writer dengan tipe data *Writer dari package bufio
    var n,k int                                     // membuat variabel n dan k dengan tipe data int
    fmt.Scan(&n,&k)                                 // menerima input data n dan k
    if (n == 1) && (k == 1) {                       // jika n sama dengan 1 dan k sama dengan 1
        fmt.Println("a")                            // maka cetak output "a"
    } else if (n < k) || (k > 26) || (k == 1) {     // jika n < k atau k > 26 atau k sama dengan 1
        fmt.Println(-1)                             // maka cetak output "-1"
    } else {
        k -= 2                                      // kurangi nilai k sebesar 2
        c, t := 'a', n-k                            // membuat variabel c tipe rune dengan nilai awal 'a' dan t tipe int dengan nilai awal n-k
        for i := 0; i < t; i++ {                    // looping sebanyak t kali
            writer.WriteRune(c)                     // mencetak output nilai c
            if c == 'a' { c = 'b' } else { c = 'a' }// jika nilai c adalah 'a' maka ubah jadi 'b' atau kebalikannya
        }
        c = 'c'                                     // isi nilai c dengan 'c'
        for i := 0; i < k; i++ {                    // looping sebanyak k kali
            writer.WriteRune(c)                     // mencetak output nilai c
            c++                                     // tambah nilai c sebesar 1 (untuk mengubah menjadi huruf selanjutnya)
        }
        writer.WriteRune('\n')                      // mencetak enter
        writer.Flush()                              // mencetak hasil output ke layar
    }
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n,k int
    fmt.Scan(&n,&k)
    if (n < k) || (k > 26) || (k == 1) {
        fmt.Println(-1)
    } else {
        k -= 2
        c, t := 'a', n-k
        for i := 0; i < t; i++ {
            writer.WriteRune(c)
            if c == 'a' { c = 'b' } else { c = 'a' }
        }
        c = 'c'
        for i := 0; i < k; i++ {
            writer.WriteRune(c)
            c++
        }
        writer.WriteRune('\n')
        writer.Flush()
    }
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n,k int
    fmt.Scan(&n,&k)
    if (n < k) || (k > 26) {
        fmt.Println(-1)
    } else {
        if k == 1 {
            for i := 0; i < n; i++ { writer.WriteRune('a') }
        } else {
            k -= 2
            c, t := 'a', n-k
            for i := 0; i < t; i++ {
                writer.WriteRune(c)
                if c == 'a' { c = 'b' } else { c = 'a' }
            }
            c = 'c'
            for i := 0; i < k; i++ {
                writer.WriteRune(c)
                c++
            }
        }
        writer.WriteRune('\n')
        writer.Flush()
    }
}


Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!

The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).

In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.

NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	b := make([]int64, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	fmt.Fscanf(reader, "%d\n", &a[n-1])
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d ", &b[i])
	}
	fmt.Fscanf(reader, "%d\n", &b[n-1])
	var ans int64
	for i := 0; i < n; i++ {
		if 2*a[i] < b[i] || b[i] == 1 {
			ans--
		} else if b[i]%2 == 0 {
			ans += (b[i] / 2) * (b[i] / 2)
		} else {
			ans += (b[i] / 2) * (b[i]/2 + 1)
		}
	}
	fmt.Printf("%d", ans)
}

package main

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

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	scanner := NewScanner(os.Stdin)
	n := scanner.nextInt()

	a, b := make([]int, n), make([]int, n)

	for i := range a {
		a[i] = scanner.nextInt()
	}

	for i := range b {
		b[i] = scanner.nextInt()
	}

	var joy int64 = 0
	var x, y int = 0, 0

	for i := range a {
		if b[i]==1 || a[i]*2 < b[i] {
			joy--
			continue
		}
		if b[i]%2==0 {
			x = b[i]/2
			y = x
		} else {
			x = b[i]/2
			y = x+1
		}
		joy += int64(x)*int64(y)
	}

	fmt.Println(joy)
}

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner(r io.Reader) *Scanner {
	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanWords)

	return &Scanner{
		scanner: scanner,
	}
}

func (s *Scanner) next() string {
	ok := s.scanner.Scan()
	if !ok {
		panic("Scan error")
	}
	return s.scanner.Text()
}

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

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

}

func (s *Scanner) SetScanLines() {
	s.scanner.Split(bufio.ScanLines)
}

func (s *Scanner) SetScanWords() {
	s.scanner.Split(bufio.ScanWords)
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	b := make([]int64, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	fmt.Fscanf(reader, "%d\n", &a[n-1])
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d ", &b[i])
	}
	fmt.Fscanf(reader, "%d\n", &b[n-1])
	var ans int64
	for i := 0; i < n; i++ {
		if 2*a[i] < b[i] {
			ans--
		} else if b[i]%2 == 0 {
			ans += (b[i] / 2) * (b[i] / 2)
		} else {
			ans += (b[i] / 2) * (b[i]/2 + 1)
		}
	}
	fmt.Printf("%d", ans)
}


You are given an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers.Find the number of pairs of indices $$$(l, r)$$$, where $$$1 \le l \le r \le n$$$, that pass the check. The check is performed in the following manner:   The minimum and maximum numbers are found among $$$a_l, a_{l+1}, \ldots, a_r$$$.  The check is passed if the maximum number is divisible by the minimum number.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.

For each test case, print a single integer — the number of pairs of indices that pass the check.

NoteBelow $$$x \mid y$$$ denotes that $$$y$$$ is divisible by $$$x$$$.In the first test case, there is one pair $$$(1, 1)$$$, the maximum for this pair is $$$1$$$, the minimum is also $$$1$$$, $$$1 \mid 1$$$, so the check is passed, and the answer is $$$1$$$.In the second test case, there are $$$3$$$ segments:   $$$(1, 1)$$$: the maximum is $$$2$$$, the minimum is $$$2$$$, $$$2 \mid 2$$$, so the check is passed.  $$$(1, 2)$$$: the maximum is $$$4$$$, the minimum is $$$2$$$, $$$2 \mid 4$$$, so the check is passed.  $$$(2, 2)$$$: the maximum is $$$4$$$, the minimum is $$$4$$$, $$$4 \mid 4$$$, so the check is passed. In the third test case, there are $$$3$$$ segments:   $$$(1, 1)$$$: the maximum is $$$2$$$, the minimum is $$$2$$$, $$$2 \mid 2$$$, so the check is passed.  $$$(1, 2)$$$: the maximum is $$$3$$$, the minimum is $$$2$$$, $$$3$$$ isn't divisible by $$$2$$$, so the check is failed.  $$$(2, 2)$$$: the maximum is $$$3$$$, the minimum is $$$3$$$, $$$3 \mid 3$$$, so the check is passed.

package main

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

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

const (
	MAX_N     = 500005
	MAX_VALUE = 1000000
)

type Stack struct {
	data []int
	rear int
}

func NewStack(size int) *Stack {
	return &Stack{
		data: make([]int, size+1),
		rear: 0,
	}
}

func (stack *Stack) Empty() bool {
	return (stack.rear == 0)
}

func (stack *Stack) Push(val int) {
	stack.data[stack.rear] = val
	stack.rear += 1
}

func (stack *Stack) Pop() {
	if stack.Empty() {
		return
	}
	stack.rear -= 1
}

func (stack *Stack) Top() int {
	if stack.Empty() {
		return -1
	}
	return stack.data[stack.rear-1]
}

func computeRange(
	size, defaultVal int,
	loop func() (int, bool),
	compare func(int, int) bool,
) []int {

	stk := NewStack(size + 1)
	ret := make([]int, size+1)

	for true {
		i, ok := loop()
		if !ok {
			break
		}

		for !stk.Empty() && compare(stk.Top(), i) {
			stk.Pop()
		}

		ret[i] = defaultVal
		if !stk.Empty() {
			ret[i] = stk.Top()
		}

		stk.Push(i)
	}

	return ret
}

func Max(args ...int) int {
	ret := args[0]
	for _, v := range args {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func Min(args ...int) int {
	ret := args[0]
	for _, v := range args {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func main() {
	defer writer.Flush()

	divs := make([][]int, MAX_VALUE+1)
	pos := make([][]int, MAX_VALUE+1)

	cursor := make([]int, MAX_VALUE+1)
	ptr := make([]int, MAX_VALUE+1)

	for i := 0; i <= MAX_VALUE; i++ {
		divs[i] = make([]int, 0)
		pos[i] = make([]int, 0)
	}

	for i := 1; i <= MAX_VALUE; i++ {
		for j := i; j <= MAX_VALUE; j += i {
			divs[j] = append(divs[j], i)
		}
	}

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

	getLoopFunc := func(start, end, D int) func() (int, bool) {
		return func() (int, bool) {
			if start != end {
				ret := start
				start += D
				return ret, true
			}
			return -1, false
		}
	}

	for ; T > 0; T-- {
		var n int
		fmt.Fscan(reader, &n)

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

			if ptr[a[i]] == len(pos[a[i]]) {
				pos[a[i]] = append(pos[a[i]], i)
			} else {
				pos[a[i]][ptr[a[i]]] = i
			}
			ptr[a[i]] += 1
		}

		lx := computeRange(
			n, -1,
			getLoopFunc(0, n, 1),
			func(i, j int) bool {
				return a[i] < a[j]
			},
		)

		rx := computeRange(
			n, n,
			getLoopFunc(n-1, -1, -1),
			func(i, j int) bool {
				return a[i] <= a[j]
			},
		)

		ly := computeRange(
			n, -1,
			getLoopFunc(0, n, 1),
			func(i, j int) bool {
				return a[i] >= a[j]
			},
		)

		ry := computeRange(
			n, n,
			getLoopFunc(n-1, -1, -1),
			func(i, j int) bool {
				return a[i] >= a[j]
			},
		)

		var ans int64 = 0

		for i := 0; i < n; i++ {
			for _, d := range divs[a[i]] {
				if cursor[d] > 0 {
					j := pos[d][cursor[d]-1]
					if j > lx[i] && i < ry[j] {
						ans += int64(j-Max(lx[i], ly[j])) * int64(Min(rx[i], ry[j])-i)
					}
				}

				if cursor[d] < ptr[d] {
					j := pos[d][cursor[d]]
					lp := -1
					if cursor[d] > 0 {
						lp = pos[d][cursor[d]-1]
					}
					if j < rx[i] && i > ly[j] {
						ans += int64(i-Max(lx[i], ly[j], lp)) * int64(Min(rx[i], ry[j])-j)
					}
				}
			}
			cursor[a[i]] += 1
		}

		fmt.Fprintf(writer, "%v\n", ans)

		// reset
		for i := 0; i < n; i++ {
			ptr[a[i]] = 0
			cursor[a[i]] = 0
		}
	}
}


Let's define the cost of a string $$$s$$$ as the number of index pairs $$$i$$$ and $$$j$$$ ($$$1 \le i < j < |s|$$$) such that $$$s_i = s_j$$$ and $$$s_{i+1} = s_{j+1}$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Among all strings with length $$$n$$$ that contain only the first $$$k$$$ characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.

The only line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5; 1 \le k \le 26$$$).

Print the string $$$s$$$ such that it consists of $$$n$$$ characters, each its character is one of the $$$k$$$ first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n,k int
	fmt.Fscan(in,&n,&k)
	nex:=[26]int{}
	var lst byte
	ans := []byte{}
	bts := []byte{}
	for i:=0;i<k;i++{
		bts = append(bts,byte(int('a')+i))
	}
	for i:=1;i<=n;i++{
		if i==1{
			lst = 'a'
			ans = append(ans,'a')
			continue
		}
		now := int(lst-'a')
		index := (nex[now]+now)%k
		ans = append(ans,bts[index])
		lst = bts[index]
		nex[now]++
	}
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fprintln(out,string(ans))
}

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

// github.com/EndlessCheng/codeforces-go
func main() {
	o := bufio.NewWriter(os.Stdout)
	var n, k, x int
	a := [26]int{}
	for Scan(&n, &k); n > 0; n-- {
		Fprintf(o, "%c", 'a'+x)
		a[x], x = (a[x]+1)%k, (x+a[x])%k
	}
	o.Flush()
}

package main

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

	var n, k int
	Fscan(in, &n, &k)

	if k == 1 {
		Fprintln(out, strings.Repeat("a", n))
		return
	}

	cnt := make([][]int, k)
	for i := range cnt {
		cnt[i] = make([]int, k)
	}
	min := func(a []int) int {
		v := a[0]
		for _, w := range a[1:] {
			if w < v {
				v = w
			}
		}
		return v
	}

	s := make([]byte, n)
	s[0] = 0
	for i := 1; i < n; i++ {
		mi := 0
		miCnt2 := int(1e9)
		pre := s[i-1]
		for j, c := range cnt[pre] {
			if c < cnt[pre][mi] {
				mi = j
				miCnt2 = min(cnt[mi])
			} else if c == cnt[pre][mi] {
				mic := min(cnt[j])
				if mic < miCnt2 {
					mi = j
					miCnt2 = mic
				}
			}
		}
		cnt[s[i-1]][mi]++
		s[i] = byte(mi)
	}

	for i := range s {
		s[i] += 'a'
	}

	Fprintln(out, string(s))
}

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

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		var a []byte
		for i := 0; i < k; i++ {
			a = append(a, byte('a'+i))
			for j := k - 1; j >= i+2; j-- {
				a = append(a, byte('a'+i))
				a = append(a, byte('a'+j))
			}

			a = append(a, byte('a'+i))

		}
		for i := k - 2; i >= 1; i-- {
			a = append(a, byte('a'+i))
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(out, string(a[i%len(a)]))

		}
	}

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

var out = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)

	var base []byte
	for i := 0; i < k; i++ {
		base = append(base, 'a')
		cur := 'a' + byte(i)
		for j := byte('b'); j <= cur; j++ {
			base = append(base, cur, j)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%c", base[i%len(base)])
	}
	fmt.Fprintln(out)
}

package main

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

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

	var n,k int
	fmt.Fscan(in,&n,&k)
	mp := map[byte]map[byte]int{}
	num := map[byte]int{}
	var lst byte
	ans := ""
	for i:=1;i<=n;i++{
		if i==1{
			lst = 'a'
			ans = ans+string(lst)
			num[lst]++
			continue
		}
		mi := 99999999
		var index byte
		for j:=0;j<=k-1;j++{
			if mp[lst]==nil{
				mp[lst]=map[byte]int{}
			}
			if mi>mp[lst][byte('a'+j)]{
				index = byte('a'+j)
				mi = mp[lst][byte('a'+j)]
			}else if mi==mp[lst][byte('a'+j)]&&num[byte('a'+j)]<num[index]{
				index = byte('a'+j)
			}
		}
		mp[lst][index]++
		ans = ans + string(index)
		lst = index
		num[lst]++
	}
	out := os.Stdout
	fmt.Fprintln(out,ans)
}

package main

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

	var n, k int
	Fscan(in, &n, &k)

	if k == 1 {
		Fprintln(out, strings.Repeat("a", n))
		return
	}

	cnt := make([][]int, k)
	for i := range cnt {
		cnt[i] = make([]int, k)
	}

	s := make([]byte, n)
	s[0] = 0
	for i := 1; i < n; i++ {
		mi := 0
		for j, c := range cnt[s[i-1]] {
			if c < cnt[s[i-1]][mi] {
				mi = j
			}
		}
		cnt[s[i-1]][mi]++
		s[i] = byte(mi)
	}

	for i := range s {
		s[i] += 'a'
	}

	Fprintln(out, string(s))
}

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

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		var a []byte
		for i := 0; i < k; i++ {
			a = append(a, byte('a'+i))
			for j := k - 1; j >= i+2; j-- {
				a = append(a, byte('a'+i))
				a = append(a, byte('a'+j))
			}

			a = append(a, byte('a'+i))

		}
		for i := k - 2; i >= 0; i-- {
			a = append(a, byte('a'+i))
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(out, string(a[i%len(a)]))

		}
	}

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

}

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