For his birthday, Kevin received the set of pairwise distinct numbers $$$1, 2, 3, \ldots, n$$$ as a gift.He is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More formally, if he arranges numbers in order $$$p_1, p_2, \ldots, p_n$$$, he wants to maximize the value $$$$$$\min \limits_{i=1}^{n - 1} \lvert p_{i + 1} - p_i \rvert,$$$$$$ where $$$|x|$$$ denotes the absolute value of $$$x$$$.Help Kevin to do that.

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The only line of each test case contains an integer $$$n$$$ ($$$2 \le n \leq 1\,000$$$) — the size of the set.

For each test case print a single line containing $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$) describing the arrangement that maximizes the minimum absolute difference of consecutive elements.  Formally, you have to print a permutation $$$p$$$ which maximizes the value $$$\min \limits_{i=1}^{n - 1} \lvert p_{i + 1} - p_i \rvert$$$. If there are multiple optimal solutions, print any of them.

NoteIn the first test case the minimum absolute difference of consecutive elements equals $$$\min \{\lvert 4 - 2 \rvert, \lvert 1 - 4 \rvert, \lvert 3 - 1 \rvert \} = \min \{2, 3, 2\} = 2$$$. It's easy to prove that this answer is optimal.In the second test case each permutation of numbers $$$1, 2, 3$$$ is an optimal answer. The minimum absolute difference of consecutive elements equals to $$$1$$$.

package main
import "fmt"

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

	m := []int{}
	answ := [][]int{}

	for s := 1; s <= t; s++ {
		fmt.Scan(&n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
		answ = append(answ, m)

	}

	for i := 0; i < t; i++ {
		for j := range answ[i] {
			fmt.Print(answ[i][j], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n int
	Fscan(r, &t)

	for t > 0{
		t--
		Fscan(r, &n)
		a := make([]int, n)
		left := make([]int, 0)
		right := make([]int, 0)
		for i := 1; i <= n/2; i++{
			left = append(left, i)
		}
		for i := n/2+1; i <= n/2*2; i++{
			right = append(right, i)
		}
		index1, index2 := len(left)-1, len(right)-1
		for i := 0; i < n/2*2; i++{
			if i % 2 == 0{
				a[i] = left[index1]
				index1--
			}else{
				a[i] = right[index2]
				index2--
			}
		}
		if n % 2 == 1{
			a[n-1] = n
		}
		for i := range a{
			if i != n - 1{
				Fprintf(w, "%d ", a[i])
			}else{
				Fprintf(w, "%d\n", a[i])
			}
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q, v [N]int
	path       []int
	maxminDiff int
	resPath    []int
)

func dfs(u int) {
	if u == n {
		res := n
		for i := 1; i < n; i++ {
			res = min(res, abs(path[i]-path[i-1]))
		}
		maxminDiff = max(maxminDiff, res)
		if res == maxminDiff {

			copy(resPath, path)
		}
		return
	}

	for i := 1; i <= n; i++ {
		if v[i] == 0 {
			v[i] = 1
			path = append(path, i)
			dfs(u + 1)
			path = path[:len(path)-1]
			v[i] = 0
		}
	}
}
func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		resPath = make([]int, n)
		// 1 2 3 4 5 6
		// 2 4 6 1 3 5    2

		// 1 2 3 4 5 6 7 8
		// 1 4 7 2 5 8 3 6
		i, j := 1, n/2+1
		// 1 2 3 4
		// 2 4 1 3
		if n%2 == 1 {
			fmt.Printf("%d ", n)
		}
		for i <= n/2 && j <= n {
			fmt.Printf("%d ", j)
			fmt.Printf("%d ", i)
			i++
			j++
		}
		// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

		// 8

		fmt.Println()
	}
}

// [5 1 6 2 7 3 8 4]
// 4 5

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

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

// B. Kevin and Permutation
package main

import "fmt"

func main(){
	var t,n int
	fmt.Scan(&t)
	for i:=0;i<t;i++ {
		fmt.Scan(&n)
		x := (n/2) + (n & 1)

		for j:=0;j<(n/2);j++{
			fmt.Println(x-j,n-j," ")
		}
		if n & 1 != 0 {
			fmt.Println(1)
		}
	}
}

package main

import "fmt"

func main() {
	var epochs, num int
	fmt.Scanf("%d\n", &epochs)
	for ; epochs > 0; epochs-- {
		fmt.Scanf("%d\n", &num)
		delta := num >> 1
		for i := 1; i <= delta; i++ {
			fmt.Printf("%d %d ", i+delta, i)
		}
		if num&1 == 1 {
			fmt.Println(num)
		} else {
			fmt.Println()
		}
	}
}

package main

import "fmt"

func main() {
	var epochs, num int
	fmt.Scanf("%d\n", &epochs)
	for ; epochs > 0; epochs-- {
		fmt.Scanf("%d\n", &num)
		delta := num & -2 >> 1
		for i := 1; i <= delta; i++ {
			fmt.Printf("%d %d ", i+delta, i)
		}
		if num&1 == 1 {
			fmt.Println(num)
		} else {
			fmt.Println()
		}
	}
}

package main

import (
	"fmt"
)

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

}
func Order(n int) {
	if n%2 == 0 {
		for i := 0; i < n-(n/2); i++ {
			fmt.Print(" ", n/2-i)
			fmt.Print(" ", n-i)
		}
	} else {
		for i := 0; i < n-(n/2); i++ {
			fmt.Print(" ", (n/2+1)-i) //3 2 1 //0 1 2 //n-(n/2) 3
			if i != n-(n/2)-1 {
				fmt.Print(" ", n-i) //5 4
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1754B
Date: 10/30/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1754/B
Problem: CF1754B
**/
func (in *CF1754B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		r, s := 0, 1
		if n%2 != 0 {
			r = ((n - 1) / 2) + 1
		} else {
			r = (n / 2) + 1
		}

		for r <= n {
			if r == n && n%2 != 0 {
				fmt.Print(r, " ")
			} else {
				fmt.Print(r, s, " ")
			}
			r++
			s++
		}
		fmt.Println()
	}
}

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

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

package main

import (
	"fmt"
)

func work() {
	var n int
	fmt.Scanln(&n)
	k := n / 2
	if n%2 == 0 {
		for i := k; i > 0; i-- {
			fmt.Printf("%d %d ", i, i+k)
		}
	} else {
		for i := k + 1; i > 1; i-- {
			fmt.Printf("%d %d ", i, i+k)
		}
		fmt.Printf("1")
	}
	fmt.Println()
}

func main() {
	var T int
	fmt.Scanln(&T)
	for i := 0; i < T; i++ {
		work()
	}
}

package main

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

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

func solve(n int) string {
	var p []int
	for i := 1; i <= n/2; i++ {
		p = append(p, i+n/2)
		p = append(p, i)
	}
	if n%2 == 1 {
		p = append(p, n)
	}
	return strings.Trim(fmt.Sprint(p), "[]")
}

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

package main

import . "fmt"
import "bufio"
import "os"

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

func ans() {
	var n int
	Fscan(in, &n)
	var a []int = make([]int, n)
	var cnt int = 1
	for i := 1; i < n; i += 2 {
		a[i] = cnt
		cnt++
	}
	for i := 0; i < n; i += 2 {
		a[i] = cnt
		cnt++
	}
	for i := 0; i < n; i++ {
		Fprint(out, a[i], " ")
	}
	Fprintln(out)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

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

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

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

		for i := 0; i < n; i++ {
			if i%2 == 0 {
				if n/2 - i/2 > 0 {
					fmt.Fprintf(w, "%d ", n/2 - i/2)
				} else {
					fmt.Fprintf(w, "%d ", n)
				}
			} else {
				fmt.Fprintf(w, "%d ", 2*(n/2) - i/2)
			}
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	if n%2 == 0 {
		val1, val2 := n/2, n
		for val1 > 0 {
			fmt.Fprint(out, val1, " ", val2, " ")
			val1--
			val2--
		}
		fmt.Fprintln(out)
	} else {
		val1, val2 := n/2+1, n
		for val1 > 1 {
			fmt.Fprint(out, val1, " ", val2, " ")
			val1--
			val2--
		}
		fmt.Fprintln(out, 1)
	}
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main
import "fmt"

func main() {
    t := 0
	n := 0
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}
	answ := [][]int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
		answ = append(answ, m)

	}

	for i := 0; i < t; i++ {
		for j := range answ[i] {
			fmt.Print(answ[i][j], " ")
		}
		fmt.Print("\n")
	}
}

package main
import "fmt"

func main() {
    t := 1
	n := 10
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}
	answ := [][]int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
		answ = append(answ, m)

	}

	for i := 0; i < t; i++ {
		for j := range answ[i] {
			fmt.Print(answ[i][j], " ")
		}
		fmt.Print("\n")
	}
}

package main
import "fmt"

func main() {
    t := 0
	n := 0
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
		for _, i := range m {
			fmt.Print(i, " ")
		}
		fmt.Print("\n")
	}
}

package main
import "fmt"

func main() {
    t := 0
	n := 0
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
		for _, i := range m {
			fmt.Print(i, " ")
		}
	}
}

package main
import "fmt"

func main() {
    t := 1
	n := 11
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}

		for _, i := range m {
		    fmt.Print(i, " ")
	    }
	}
}

package main
import "fmt"

func main() {
    t := 1
	n := 11
	k := 0
    fmt.Scanf("%d", &t)

	m := []int{}

	for s := 1; s <= t; s++ {
		fmt.Scanf("%d", &n)
		m = []int{}
		if n % 2 == 0 {
			k = n / 2
			for i := k + 1; i <= n; i ++ {
				m = append(m, i)
				m = append(m, i - k)
			}
		} else {
			k = n / 2
			m = append(m, k + 1)
			for i := 1; i <= k; i ++ {
				m = append(m, i)
				m = append(m, i + k + 1)
			}
		}
	}

	for _, i := range m {
		fmt.Print(i, " ")
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n int
	Fscan(r, &t)

	for t > 0{
		t--
		Fscan(r, &n)
		if n == 4{
			a := []int{2,4,1,3}
			for i := range a{
				if i != n - 1{
					Fprintf(w, "%d ", a[i])
				}else{
					Fprintf(w, "%d\n", a[i])
				}
			}
			continue
		}
		a := make([]int, n)
		left := make([]int, 0)
		right := make([]int, 0)
		for i := 1; i <= (n+1)/2; i++{
			left = append(left, i)
		}
		for i := (n+1)/2+1; i <= n; i++{
			right = append(right, i)
		}
		index1, index2 := 0, 0
		for i := 0; i < n; i++{
			if i % 2 == 0{
				a[i] = left[index1]
				index1++
			}else{
				a[i] = right[index2]
				index2++
			}
		}
		for i := range a{
			if i != n - 1{
				Fprintf(w, "%d ", a[i])
			}else{
				Fprintf(w, "%d\n", a[i])
			}
		}
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n int
	Fscan(r, &t)

	for t > 0{
		t--
		Fscan(r, &n)
		if n == 4{
			a := []int{1,3,4,2}
			for i := range a{
				if i != n - 1{
					Fprintf(w, "%d ", a[i])
				}else{
					Fprintf(w, "%d\n", a[i])
				}
			}
			continue
		}
		a := make([]int, n)
		left := make([]int, 0)
		right := make([]int, 0)
		for i := 1; i <= (n+1)/2; i++{
			left = append(left, i)
		}
		for i := (n+1)/2+1; i <= n; i++{
			right = append(right, i)
		}
		index1, index2 := 0, 0
		for i := 0; i < n; i++{
			if i % 2 == 0{
				a[i] = left[index1]
				index1++
			}else{
				a[i] = right[index2]
				index2++
			}
		}
		for i := range a{
			if i != n - 1{
				Fprintf(w, "%d ", a[i])
			}else{
				Fprintf(w, "%d\n", a[i])
			}
		}
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n int
	Fscan(r, &t)

	for t > 0{
		t--
		Fscan(r, &n)
		a := make([]int, n)
		left := make([]int, 0)
		right := make([]int, 0)
		for i := 1; i <= (n+1)/2; i++{
			left = append(left, i)
		}
		for i := (n+1)/2+1; i <= n; i++{
			right = append(right, i)
		}
		index1, index2 := 0, 0
		for i := 0; i < n; i++{
			if i % 2 == 0{
				a[i] = left[index1]
				index1++
			}else{
				a[i] = right[index2]
				index2++
			}
		}
		for i := range a{
			Fprintf(w, "%d ", a[i])
		}
		Fprintln(w,)
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t, n int
	Fscan(r, &t)

	for t > 0{
		t--
		Fscan(r, &n)
		a := make([]int, n)
		left := make([]int, 0)
		right := make([]int, 0)
		for i := 1; i <= (n+1)/2; i++{
			left = append(left, i)
		}
		for i := (n+1)/2+1; i <= n; i++{
			right = append(right, i)
		}
		index1, index2 := 0, 0
		for i := 0; i < n; i++{
			if i % 2 == 0{
				a[i] = left[index1]
				index1++
			}else{
				a[i] = right[index2]
				index2++
			}
		}
		for i := range a{
			if i != n - 1{
				Fprintf(w, "%d ", a[i])
			}else{
				Fprintf(w, "%d\n", a[i])
			}
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int

	fmt.Fscan(reader, &t)
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		// 1 2 3 4 5 6
		// 2 4 6 1 3 5    2

		// 1 2 3 4 5 6 7 8
		// 1 4 7 2 5 8 3 6
		step := 1
		// 1 2 3 4
		// 2 4 1 3

		for {
			remain := n / step
			if remain <= step {
				break
			} else {
				step++
			}
		}
		for i := step; i >= 1; i-- {
			for j := i; j <= n; j += step {
				fmt.Printf("%d ", j)
			}
		}

		fmt.Println()
	}
}

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

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int

	fmt.Fscan(reader, &t)
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		// 1 2 3 4 5 6
		// 2 4 6 1 3 5    2

		// 1 2 3 4 5 6 7 8
		// 1 4 7 2 5 8 3 6
		step := 1
		// 1 2 3 4
		// 2 4 1 3

		for {
			remain := n / step
			if remain <= step {
				break
			} else {
				step++
			}
		}
		fmt.Println(step)
		for i := step; i >= 1; i-- {
			for j := i; j <= n; j += step {
				fmt.Printf("%d ", j)
			}
		}

		fmt.Println()
	}
}

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

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int

	fmt.Fscan(reader, &t)
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		// 1 2 3 4 5 6
		// 2 4 6 1 3 5    2

		// 1 2 3 4 5 6 7 8
		// 1 4 7 2 5 8 3 6
		step := 1
		// 4, 6,
		//
		for {
			remain := n / step
			if remain < step {
				break
			} else {
				step++
			}
		}
		for i := 1; i <= step; i++ {
			for j := i; j <= n; j += step {
				fmt.Printf("%d ", j)
			}
		}

		fmt.Println()
	}
}

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

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int

	fmt.Fscan(reader, &t)
	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		// 1 2 3 4
		// 2 4 1 3
		// 1 2 3 4 5 6
		// 2 4 6 1 3 5    2
		// 1 2 3 4 5 6    1

		// 1 2 3 4 5
		// 2 4 1 3 5

		for i := 2; i <= n; i += 2 {
			fmt.Printf("%d ", i)
		}

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

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

// B. Kevin and Permutation
package main

import "fmt"

func main(){
	var t,n,i int
	fmt.Scan(&t)
	for t != 0 {
		i = 1
		fmt.Scan(&n)
		for i<=n/2 {
			fmt.Println((i+n/2), " ", i, " ")
			i++
			if n%2 != 0 {
				fmt.Println(n)
			}
		}
		t--
	}
}

// B. Kevin and Permutation
package main

import "fmt"

func main(){
	var t,n,i int
	fmt.Scan(&t)
	for t != 0 {
		i = 1
		fmt.Scan(&n)
		for i<=n/2 {
			fmt.Print((i+n/2), " ", i, " ")
			i++
			if n%2 != 0 {
				fmt.Print(n)
			}
		}
		t--
	}
}

package main

import "fmt"

func main() {
	var epochs, num int
	fmt.Scanf("%d\n", &epochs)
	for ; epochs > 0; epochs-- {
		fmt.Scanf("%d\n", &num)
		stack := make([]int, 0, num)
		delta := (num + 1) / 2
		for i := 1; i < delta; i++ {
			stack = append(stack, i+delta, i)
		}
		if num&1 == 1 {
			stack = append(stack, delta)
		} else {
			stack = append(stack, delta+delta, delta)
		}
		for i := len(stack) - 1; i > 0; i-- {
			fmt.Printf("%d ", stack[i])
		}
		fmt.Printf("%d\n", stack[0])
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		var arr = make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = i + 1
		}
		for i := 0; i < n; i++ {
			fmt.Print(arr[i])
		}
	}

}
func Swap() {

}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1754B
Date: 10/30/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1754/B
Problem: CF1754B
**/
func (in *CF1754B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		if n == 4 {
			fmt.Println("2 4 1 3")
			continue
		}
		for i := 1; i <= n; i++ {
			if i%2 != 0 {
				fmt.Print(i, " ")
			}
		}
		for i := 1; i <= n; i++ {
			if i%2 == 0 {
				fmt.Print(i, " ")
			}
		}
		fmt.Println()
	}
}

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

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


An array $$$b$$$ is called to be a subarray of $$$a$$$ if it forms a continuous subsequence of $$$a$$$, that is, if it is equal to $$$a_l$$$, $$$a_{l + 1}$$$, $$$\ldots$$$, $$$a_r$$$ for some $$$l, r$$$.Suppose $$$m$$$ is some known constant. For any array, having $$$m$$$ or more elements, let's define it's beauty as the sum of $$$m$$$ largest elements of that array. For example:   For array $$$x = [4, 3, 1, 5, 2]$$$ and $$$m = 3$$$, the $$$3$$$ largest elements of $$$x$$$ are $$$5$$$, $$$4$$$ and $$$3$$$, so the beauty of $$$x$$$ is $$$5 + 4 + 3 = 12$$$. For array $$$x = [10, 10, 10]$$$ and $$$m = 2$$$, the beauty of $$$x$$$ is $$$10 + 10 = 20$$$.You are given an array $$$a_1, a_2, \ldots, a_n$$$, the value of the said constant $$$m$$$ and an integer $$$k$$$. Your need to split the array $$$a$$$ into exactly $$$k$$$ subarrays such that:  Each element from $$$a$$$ belongs to exactly one subarray. Each subarray has at least $$$m$$$ elements. The sum of all beauties of $$$k$$$ subarrays is maximum possible.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m$$$, $$$2 \le k$$$, $$$m \cdot k \le n$$$) — the number of elements in $$$a$$$, the constant $$$m$$$ in the definition of beauty and the number of subarrays to split to. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$).

In the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition. In the second line, print $$$k-1$$$ integers $$$p_1, p_2, \ldots, p_{k-1}$$$ ($$$1 \le p_1 < p_2 < \ldots < p_{k-1} < n$$$) representing the partition of the array, in which:  All elements with indices from $$$1$$$ to $$$p_1$$$ belong to the first subarray. All elements with indices from $$$p_1 + 1$$$ to $$$p_2$$$ belong to the second subarray. $$$\ldots$$$. All elements with indices from $$$p_{k-1} + 1$$$ to $$$n$$$ belong to the last, $$$k$$$-th subarray. If there are several optimal partitions, print any of them.

NoteIn the first example, one of the optimal partitions is $$$[5, 2, 5]$$$, $$$[2, 4]$$$, $$$[1, 1, 3, 2]$$$.  The beauty of the subarray $$$[5, 2, 5]$$$ is $$$5 + 5 = 10$$$.  The beauty of the subarray $$$[2, 4]$$$ is $$$2 + 4 = 6$$$.  The beauty of the subarray $$$[1, 1, 3, 2]$$$ is $$$3 + 2 = 5$$$. The sum of their beauties is $$$10 + 6 + 5 = 21$$$.In the second example, one optimal partition is $$$[4]$$$, $$$[1, 3]$$$, $$$[2, 2]$$$, $$$[3]$$$.

package main

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

type Val struct {
    index int
    value int
}

type Vals []Val

func (a Vals) greaterValue(i, j int) bool {
    return a[i].value > a[j].value
}

func (a Vals) lessIndex(i, j int) bool {
    return a[i].index < a[j].index
}
func main() {
    stdin := bufio.NewReader(os.Stdin)
    var n, m, k int
    st := time.Now()
    fmt.Fscanf(stdin, "%d %d %d\n", &n, &m, &k)
    a := make(Vals, n)
    for i := 0; i < n; i++ {
        a[i].index = i + 1
        fmt.Fscanf(stdin, "%d", &a[i].value)
    }
    debug := false
    //  if k == 56945 {
    if k == 10000 {
        debug = true
    }
    if debug {
        fmt.Println("read ok", time.Now().Sub(st).Nanoseconds())
    }
    sort.Slice(a, a.greaterValue)
    if debug {
        fmt.Println("sort ok", time.Now().Sub(st).Nanoseconds())
    }

    b := a[:m*k]
    sort.Slice(b, b.lessIndex)
    sum := int64(0)
    for i := 0; i < m*k; i++ {
        sum += int64(b[i].value)
    }
    fmt.Println(sum)
    if debug {
        fmt.Println("fmt print ok", time.Now().Sub(st).Nanoseconds())
    }
    for i := 0; i < k-1; i++ {
        if i > 0 {
            fmt.Printf(" ")
        }
        fmt.Printf("%d", b[i*m+m-1].index)
    }
    fmt.Println()
}

package main

import (
    "fmt"
    "sort"
)

type Val struct {
    index int
    value int
}

type Vals []Val

func (a Vals) greaterValue(i, j int) bool {
    return a[i].value > a[j].value
}

func (a Vals) lessIndex(i, j int) bool {
    return a[i].index < a[j].index
}
func main() {
    var n, m, k int
    fmt.Scanf("%d %d %d", &n, &m, &k)
    a := make(Vals, n)
    for i := 0; i < n; i++ {
        a[i].index = i + 1
        fmt.Scanf("%d", &a[i].value)
    }
    debug := false
    if k == 56945 {
        debug = true
    }
    if debug {
        fmt.Println("read ok")
    }
    sort.Slice(a, a.greaterValue)
    if debug {
        fmt.Println("sort ok")
    }

    b := a[:m*k]
    sort.Slice(b, b.lessIndex)
    sum := int64(0)
    for i := 0; i < m*k; i++ {
        sum += int64(b[i].value)
    }
    fmt.Println(sum)
    for i := 0; i < k-1; i++ {
        if i > 0 {
            fmt.Printf(" ")
        }
        fmt.Printf("%d", b[i*m+m-1].index)
    }
    fmt.Println()
}

package main

import (
    "fmt"
    "sort"
)

type Val struct {
    index int
    value int
}

type Vals []Val

func (a Vals) greaterValue(i, j int) bool {
    return a[i].value > a[j].value
}

func (a Vals) lessIndex(i, j int) bool {
    return a[i].index < a[j].index
}
func main() {
    var n, m, k int
    fmt.Scanf("%d %d %d", &n, &m, &k)
    a := make(Vals, n)
    for i := 0; i < n; i++ {
        a[i].index = i + 1
        fmt.Scanf("%d", &a[i].value)
    }
    sort.Slice(a, a.greaterValue)

    b := a[:m*k]
    sort.Slice(b, b.lessIndex)
    sum := int64(0)
        for i := 0; i < m*k; i++ {
        sum += int64(b[i].value)
    }
    fmt.Println(sum)
    for i := 0; i < k-1; i++ {
        if i > 0 {
            fmt.Printf(" ")
        }
        fmt.Printf("%d", b[i*m+m-1].index)
    }
    fmt.Println()
}

package main

import (
    "fmt"
    "sort"
    "time"
)

type Val struct {
    index int
    value int
}

type Vals []Val

func (a Vals) greaterValue(i, j int) bool {
    return a[i].value > a[j].value
}

func (a Vals) lessIndex(i, j int) bool {
    return a[i].index < a[j].index
}
func main() {
    var n, m, k int
    st := time.Now()
    fmt.Scanf("%d %d %d", &n, &m, &k)
    a := make(Vals, n)
    for i := 0; i < n; i++ {
        a[i].index = i + 1
        fmt.Scanf("%d", &a[i].value)
    }
    debug := false
    if k == 56945 {
        debug = true
    }
    if debug {
        fmt.Println("read ok", time.Now().Sub(st).Nanoseconds())
    }
    sort.Slice(a, a.greaterValue)
    if debug {
        fmt.Println("sort ok", time.Now().Sub(st).Nanoseconds())
    }

    b := a[:m*k]
    sort.Slice(b, b.lessIndex)
    sum := int64(0)
    for i := 0; i < m*k; i++ {
        sum += int64(b[i].value)
    }
    fmt.Println(sum)
    if debug {
        fmt.Println("fmt print ok", time.Now().Sub(st).Nanoseconds())
    }
    for i := 0; i < k-1; i++ {
        if i > 0 {
            fmt.Printf(" ")
        }
        fmt.Printf("%d", b[i*m+m-1].index)
    }
    fmt.Println()
}


Monocarp plays "Rage of Empires II: Definitive Edition" — a strategic computer game. Right now he's planning to attack his opponent in the game, but Monocarp's forces cannot enter the opponent's territory since the opponent has built a wall.The wall consists of $$$n$$$ sections, aligned in a row. The $$$i$$$-th section initially has durability $$$a_i$$$. If durability of some section becomes $$$0$$$ or less, this section is considered broken.To attack the opponent, Monocarp needs to break at least two sections of the wall (any two sections: possibly adjacent, possibly not). To do this, he plans to use an onager — a special siege weapon. The onager can be used to shoot any section of the wall; the shot deals $$$2$$$ damage to the target section and $$$1$$$ damage to adjacent sections. In other words, if the onager shoots at the section $$$x$$$, then the durability of the section $$$x$$$ decreases by $$$2$$$, and the durability of the sections $$$x - 1$$$ and $$$x + 1$$$ (if they exist) decreases by $$$1$$$ each. Monocarp can shoot at any sections any number of times, he can even shoot at broken sections.Monocarp wants to calculate the minimum number of onager shots needed to break at least two sections. Help him!

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of sections. The second line contains the sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th section.

Print one integer — the minimum number of onager shots needed to break at least two sections of the wall.

NoteIn the first example, it is possible to break the $$$2$$$-nd and the $$$4$$$-th section in $$$10$$$ shots, for example, by shooting the third section $$$10$$$ times. After that, the durabilities become $$$[20, 0, 10, 0, 20]$$$. Another way of doing it is firing $$$5$$$ shots at the $$$2$$$-nd section, and another $$$5$$$ shots at the $$$4$$$-th section. After that, the durabilities become $$$[15, 0, 20, 0, 15]$$$.In the second example, it is enough to shoot the $$$2$$$-nd section once. Then the $$$1$$$-st and the $$$3$$$-rd section will be broken.In the third example, it is enough to shoot the $$$2$$$-nd section twice (then the durabilities become $$$[5, 2, 4, 8, 5, 8]$$$), and then shoot the $$$3$$$-rd section twice (then the durabilities become $$$[5, 0, 0, 6, 5, 8]$$$). So, four shots are enough to break the $$$2$$$-nd and the $$$3$$$-rd section.

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min = [2]int{sections[0], math.MaxInt}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration1 > duration2 {
		if shot < duration1/2+duration1%2 {
			shot = duration1/2 + duration1%2
		}
	} else {
		if shot < duration2/2+duration2%2 {
			shot = duration2/2 + duration2%2
		}
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

package main

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

var N int64
var A []int64

var MX int64 = 10000000

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

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

func solve() int64 {
	res := MX
	for i := int64(0); i < N; i++ {
		n1 := (A[i] + 1) / 2
		cur1, cur2, cur3 := MX, MX, MX
		if i+1 < N {
			cur1 = n1
			if A[i+1] > n1 {
				cur1 += (A[i+1] - n1 + 1) / 2
			}
		}

		if i-1 >= 0 {
			cur2 = n1
			if A[i-1] > n1 {
				cur2 += (A[i-1] - n1 + 1) / 2
			}
		}

		if i+1 < N && i-1 >= 0 {
			a, b := min(A[i-1], A[i+1]), max(A[i-1], A[i+1])
			cur3 = a
			cur3 += (b - a + 1) / 2
			res = min(res, cur3)
		}

		res = min(res, cur1)
		res = min(res, cur2)
		res = min(res, cur3)

		//fmt.Println(cur1, cur2, cur3, res)
	}

	for i := int64(0); i < N-1; i++ {
		a, b := A[i], A[i+1]
		if a > b {
			a, b = b, a
		}

		cur := b - a
		a = 2*a - b
		if a > 0 {
			cur += a/3*2 + a%3
		}
		res = min(res, cur)
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})

	res = min(res, (A[0]+1)/2+(A[1]+1)/2)
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &N)
	A = make([]int64, N)
	for i := int64(0); i < N; i++ {
		fmt.Fscan(reader, &A[i])
	}

	fmt.Println(solve())
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func I(a int) int64 { return int64(a) }
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gi2() (int64,int64) { return gi(),gi() }
func gi3() (int64,int64,int64) { return gi(),gi(),gi() }
func gi4() (int64,int64,int64,int64) { return gi(),gi(),gi(),gi() }
func gis(n int64) []int64 { res := make([]int64,n); for i:=I(0);i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int64) []float64  { res := make([]float64,n); for i:=I(0);i<n;i++ { res[i] = gf() }; return res }
func gss(n int64) []string  { res := make([]string,n); for i:=I(0);i<n;i++ { res[i] = gs() }; return res }
func ia(m int64) []int64 { return make([]int64,m) }
func iai(m int64,v int64) []int64 { a := make([]int64,m); for i:=I(0);i<m;i++ { a[i] = v }; return a }
func twodi(n int64,m int64,v int64) [][]int64 {
	r := make([][]int64,n); for i:=I(0);i<n;i++ { x := make([]int64,m); for j:=I(0);j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int64) ([]int64,[]int64) { a,b := ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int64) ([]int64,[]int64,[]int64) { a,b,c := ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int64) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int64) int64 { if a < 0 { return -a }; return a }
func rev(a []int64) { i,j := I(0),I(len(a)-1); for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int64) int64 { if a > b { return a }; return b }
func min(a,b int64) int64 { if a > b { return b }; return a }
func tern(cond bool, a int64, b int64) int64 { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int64) int64 { ans := I(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int64) { for i:=I(0); i<I(len(a)); i++ { a[i] = 0 } }
func powmod(a,e,mod int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int64) (int64,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=I(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
const inf int64 = 1000000000000000000
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); A := gis(N)
	best,s1,s2 := inf,inf,inf
	// Possibility 1, we shoot down two non-adjacent walls
	for _,a := range A { b := (a+1)/2; if b <= s1 { s1,s2 = b,s1 } else if b <= s2 { s2 = b } }
	best = s1+s2
	// Possibility 2, we shoot down two adjacent walls
	solveadjpair := func(a,b int64) int64 {
		if a < b { a,b = b,a }
		ans := (a+1)/2;
		if b > ans {
			ans = a-b; a -= 2*ans; b-= ans
			tt := a/3; ans += 2*tt; a -= 3*tt
			if a == 1 { ans++ } else if a == 2 { ans += 2 }
		}
		//fmt.Fprintf(wrtr,"DBG: solvepair:(%v,%v) = %v\n",a,b,ans)
		return ans
	}
	// Possibility 3, we shoot down two walls that have a one space gap
	solvenonadjpair := func(a,b int64) int64 {
		if a < b { a,b = b,a }
		return b + (a-b+1)/2
	}

	//fmt.Fprintf(wrtr,"DBG: best before solvepair:%v\n",best)
	for i:=I(0);i+1<N;i++ { cand := solveadjpair(A[i],A[i+1]); best = min(best,cand) }
	for i:=I(0);i+2<N;i++ { cand := solvenonadjpair(A[i],A[i+2]); best = min(best,cand) }
	fmt.Fprintln(wrtr,best)
}

package main

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

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

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

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

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

	arr := make([]int, n)
	m1, m2 := math.MaxInt32, math.MaxInt32
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])

		if m1 > arr[i] {
			m1, m2 = arr[i], m1
		} else if m2 > arr[i] {
			m2 = arr[i]
		}
	}

	ans := (m1+1)/2 + (m2+1)/2
	for i := 0; i < n-2; i++ {
		ans = min(ans, (arr[i]+arr[i+2]+1)/2)
	}
	for i := 0; i < n-1; i++ {
		ans = min(ans, max((arr[i]+1)/2, (arr[i+1]+1)/2, (arr[i]+arr[i+1]+2)/3))
	}

	fmt.Fprintln(out, ans)
}

package main

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

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

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

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

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

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

	m1, m2 := math.MaxInt32, math.MaxInt32
	for _, v := range arr {
		if v < m1 {
			m1, m2 = v, m1
		} else if v < m2 {
			m2 = v
		}
	}

	resp := (m1+1)/2 + (m2+1)/2
	for i := 0; i < n-2; i++ {
		resp = min(resp, (arr[i]+arr[i+2]+1)/2)
	}

	for i := 0; i < n-1; i++ {
		resp = min(resp, max((arr[i]+1)/2, (arr[i+1]+1)/2, (arr[i]+arr[i+1]+2)/3))
	}

	fmt.Fprintln(out, resp)
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func getAns(a int, b int) int {
	ans := 100_000_000

	l, r := 0, 10_000_000

	count := func(k1 int) int {
		ak2 := a - k1*2
		bk2 := (b-k1)/2 + (b-k1)%2
		k2 := max(max(ak2, bk2), 0)
		return k1 + k2
	}

	for r-l > 5 {
		x1 := l + (r-l)/3
		x2 := r - (r-l)/3

		if count(x1) < count(x2) {
			r = x2
		} else {
			l = x1
		}
	}

	for i := l; i <= r; i++ {
		ans = min(ans, count(i))
	}

	return ans
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	n := io.ReadInt()
	a := io.ReadIntSlice(n)

	ans := 100_000_000

	for i := 1; i < len(a)-1; i++ {
		mx := max(a[i-1], a[i+1])
		mn := min(a[i-1], a[i+1])
		dop := (mx-mn)/2 + (mx-mn)%2
		ans = min(ans, mn+dop)
	}

	for i := 0; i < len(a)-1; i++ {
		ans = min(ans, getAns(a[i], a[i+1]))
	}

	sort.Ints(a)
	ans = min(ans, a[0]/2+a[0]%2+a[1]/2+a[1]%2)

	fmt.Println(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1674E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	fi, se := int(1e9), int(1e9)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] < fi {
			fi, se = a[i], fi
		} else if a[i] < se {
			se = a[i]
		}
	}
	ans := (fi+1)/2 + (se+1)/2
	for i := 1; i < n; i++ {
		v, w := a[i-1], a[i]
		if i < n-1 {
			m := min(v, a[i+1])
			ans = min(ans, m+(max(v, a[i+1])-m+1)/2)
		}
		if v < w {
			v, w = w, v
		}
		if v >= w*2 {
			ans = min(ans, (v+1)/2)
		} else {
			d := v - w
			w -= d
			ans = min(ans, d+w/3*2+w%3)
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

//func max(a, b int) int {if a > b {return a} else {return b}}
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	left, right := make([]int, n), make([]int, n)
	left[0] = math.MaxInt
	right[n-1] = math.MaxInt
	two := make([]int, n)
	for i:=1;i<n;i++ {
		left[i] = min(left[i-1], nums[i-1])
	}
	for i:=n-2;i>=0;i-- {
		right[i] = min(right[i+1], nums[i+1])
	}
	ans := math.MaxInt
	for i:=0;i<n-1;i++ {
		var a, b int
		if nums[i] > nums[i+1] {
			a, b = nums[i], nums[i+1]
		} else{
			a, b = nums[i+1], nums[i]
		}
		if a > 2 * b {
			two[i] = (a+1)/2
		} else {
			two[i] = (a+b+2)/3
		}
		ans = min(ans, two[i])
	}
	for i := range nums {
		cur := (nums[i]+1)/2
		m := min(left[i], right[i])
		cur += (m+1)/2
		ans = min(ans, cur)
	}
	for i:=1;i<n-1;i++ {
		m := min(nums[i-1], nums[i+1])
		mm := max(nums[i-1], nums[i+1])
		ans = min(ans, m+(mm-m+1)/2)
	}
	fmt.Fprintln(w, ans)
}

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

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min = [2]int{sections[0], math.MaxInt}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration1 > duration2+duration1%2 {
		if shot < duration1/2 {
			shot = duration1/2 + duration1%2
		}
	} else {
		if shot < duration2/2+duration2%2 {
			shot = duration2/2 + duration2%2
		}
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min = [2]int{sections[0], math.MaxInt}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration1 > duration2 {
		if shot < duration1/2 {
			shot = duration1/2 + duration1%2
		}
	} else {
		if shot < duration2/2 {
			shot = duration2/2 + duration2%2
		}
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min = [2]int{sections[0], math.MaxInt}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration1 > duration2 {
		if shot < duration1/2 {
			shot = duration1/2 + duration1%2
		}
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min = [2]int{sections[0], math.MaxInt}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Fscan(in, &sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Fscan(in, &sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min [2]int
	if sections[0] < sections[1] {
		min = [2]int{sections[0], sections[1]}
	} else {
		min = [2]int{sections[1], sections[0]}
	}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

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

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var sectionNum int
	fmt.Scanln(&sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Scanln(&sections[i])
	}
	fmt.Fprintln(out, breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min [2]int
	if sections[0] < sections[1] {
		min = [2]int{sections[0], sections[1]}
	} else {
		min = [2]int{sections[1], sections[0]}
	}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var sectionNum int
	fmt.Scanln(&sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Scanln(&sections[i])
	}
	print(breakTheWall(sections))
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min [2]int
	if sections[0] < sections[1] {
		min = [2]int{sections[0], sections[1]}
	} else {
		min = [2]int{sections[1], sections[0]}
	}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var sectionNum int
	fmt.Scanln(&sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Scanln(&sections[i])
	}
	breakTheWall(sections)
}

func breakTheWall(sections []int) int {
	var max = math.MaxInt
	var min [2]int
	if sections[0] < sections[1] {
		min = [2]int{sections[0], sections[1]}
	} else {
		min = [2]int{sections[1], sections[0]}
	}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	return max
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

// hello.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var sectionNum int
	fmt.Scanln(&sectionNum)
	sections := make([]int, sectionNum)
	for i := 0; i < sectionNum; i++ {
		fmt.Scanln(&sections[i])
	}
	breakTheWall(sections)
}

func breakTheWall(sections []int) {
	var max = math.MaxInt
	var min [2]int
	if sections[0] < sections[1] {
		min = [2]int{sections[0], sections[1]}
	} else {
		min = [2]int{sections[1], sections[0]}
	}
	for i := 0; i < len(sections)-1; i++ {
		if min[1] > sections[i+1] {
			if min[0] > sections[i+1] {
				min[1] = min[0]
				min[0] = sections[i+1]
			} else {
				min[1] = sections[i+1]
			}
		}
		if i+2 >= len(sections) {
			temp := getShot(sections[i], sections[i+1], 0)
			if max > temp {
				max = temp
			}
		} else {
			temp := getShot(sections[i], sections[i+1], sections[i+2])
			if max > temp {
				max = temp
			}
		}
	}
	if min[0]/2+min[0]%2+min[1]/2+min[1]%2 < max {
		max = min[0]/2 + min[0]%2 + min[1]/2 + min[1]%2
	}
	println(max)
}

func getShot(duration1, duration2, duration3 int) int {
	var shot int
	if (duration1+duration2)%3 != 0 {
		shot = (duration1+duration2)/3 + 1
	} else {
		shot = (duration1 + duration2) / 3
	}
	if duration3 != 0 && ((duration1+duration3)/2 < shot) {
		shot = (duration1+duration3)/2 + (duration1+duration3)%2
	}
	return shot
}

package main

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

var N int64
var A []int64

var MX int64 = 10000000

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

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

func solve() int64 {
	res := MX
	for i := int64(0); i < N; i++ {
		n1 := (A[i] + 1) / 2
		cur1, cur2, cur3 := MX, MX, MX
		if i+1 < N {
			cur1 = n1
			if A[i+1] > n1 {
				cur1 += (A[i+1] - n1 + 1) / 2
			}
		}

		if i-1 >= 0 {
			cur2 = n1
			if A[i-1] > n1 {
				cur2 += (A[i-1] - n1 + 1) / 2
			}
		}

		if i+1 < N && i-1 >= 0 {
			cur3 = max(A[i-1], A[i+1])
		}
		res = min(res, cur1)
		res = min(res, cur2)
		res = min(res, cur3)

		//fmt.Println(cur1, cur2, cur3, res)
	}

	for i := int64(0); i < N-1; i++ {
		a, b := A[i], A[i+1]
		if a > b {
			a, b = b, a
		}

		cur := b - a
		a = 2*a - b
		if a > 0 {
			cur += a/3*2 + a%3
		}
		res = min(res, cur)
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})

	res = min(res, (A[0]+1)/2+(A[1]+1)/2)
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &N)
	A = make([]int64, N)
	for i := int64(0); i < N; i++ {
		fmt.Fscan(reader, &A[i])
	}

	fmt.Println(solve())
}

package main

import (
	"fmt"
	"sort"
)

var N int64
var A []int64

var MX int64 = 10000000

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

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

func solve() int64 {
	res := MX
	for i := int64(0); i < N; i++ {
		n1 := (A[i] + 1) / 2
		cur1, cur2, cur3 := MX, MX, MX
		if i+1 < N {
			cur1 = n1
			if A[i+1] > n1 {
				cur1 += (A[i+1] - n1 + 1) / 2
			}
		}

		if i-1 >= 0 {
			cur2 = n1
			if A[i-1] > n1 {
				cur2 += (A[i-1] - n1 + 1) / 2
			}
		}

		if i+1 < N && i-1 >= 0 {
			cur3 = max(A[i-1], A[i+1])
		}
		res = min(res, cur1)
		res = min(res, cur2)
		res = min(res, cur3)

		//fmt.Println(cur1, cur2, cur3, res)
	}

	for i := int64(0); i < N-1; i++ {
		a, b := A[i], A[i+1]
		if a > b {
			a, b = b, a
		}

		cur := b - a
		a = 2*a - b
		cur += a/3*2 + a%3
		res = min(res, cur)
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})

	res = min(res, (A[0]+1)/2+(A[1]+1)/2)
	return res
}

func main() {
	fmt.Scanf("%d\n", &N)
	A = make([]int64, N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	fmt.Println(solve())
}

package main

import (
	"fmt"
	"sort"
)

var N int64
var A []int64

var MX int64 = 10000000

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

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

func solve() int64 {
	res := MX
	for i := int64(0); i < N; i++ {
		n1 := (A[i] + 1) / 2
		cur1, cur2, cur3 := MX, MX, MX
		if i+1 < N {
			cur1 = n1
			if A[i+1] > n1 {
				cur1 += (A[i+1] - n1 + 1) / 2
			}
		}

		if i-1 >= 0 {
			cur2 = n1
			if A[i-1] > n1 {
				cur2 += (A[i-1] - n1 + 1) / 2
			}
		}

		if i+1 < N && i-1 >= 0 {
			cur3 = max(A[i-1], A[i+1])
		}
		res = min(res, cur1)
		res = min(res, cur2)
		res = min(res, cur3)

		//fmt.Println(cur1, cur2, cur3, res)
	}

	for i := int64(0); i < N-1; i++ {
		a, b := A[i], A[i+1]
		step := int64(0)
		for a > 0 || b > 0 {
			if a < b {
				b -= 2
				a -= 1
			} else {
				a -= 2
				b -= 1
			}
			step++
		}
		res = min(res, step)
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})

	res = min(res, (A[0]+1)/2+(A[1]+1)/2)
	return res
}

func main() {
	fmt.Scanf("%d", &N)
	A = make([]int64, N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	fmt.Println(solve())
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func I(a int) int64 { return int64(a) }
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gi2() (int64,int64) { return gi(),gi() }
func gi3() (int64,int64,int64) { return gi(),gi(),gi() }
func gi4() (int64,int64,int64,int64) { return gi(),gi(),gi(),gi() }
func gis(n int64) []int64 { res := make([]int64,n); for i:=I(0);i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int64) []float64  { res := make([]float64,n); for i:=I(0);i<n;i++ { res[i] = gf() }; return res }
func gss(n int64) []string  { res := make([]string,n); for i:=I(0);i<n;i++ { res[i] = gs() }; return res }
func ia(m int64) []int64 { return make([]int64,m) }
func iai(m int64,v int64) []int64 { a := make([]int64,m); for i:=I(0);i<m;i++ { a[i] = v }; return a }
func twodi(n int64,m int64,v int64) [][]int64 {
	r := make([][]int64,n); for i:=I(0);i<n;i++ { x := make([]int64,m); for j:=I(0);j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int64) ([]int64,[]int64) { a,b := ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int64) ([]int64,[]int64,[]int64) { a,b,c := ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int64) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int64) int64 { if a < 0 { return -a }; return a }
func rev(a []int64) { i,j := I(0),I(len(a)-1); for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int64) int64 { if a > b { return a }; return b }
func min(a,b int64) int64 { if a > b { return b }; return a }
func tern(cond bool, a int64, b int64) int64 { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int64) int64 { ans := I(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int64) { for i:=I(0); i<I(len(a)); i++ { a[i] = 0 } }
func powmod(a,e,mod int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int64) (int64,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=I(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
const inf int64 = 1000000000000000000
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); A := gis(N)
	if N == 3 { fmt.Fprintf(wrtr,"DBG: N:%v A:%v\n",N,A) }
	best,s1,s2 := inf,inf,inf
	// Possibility 1, we shoot down two non-adjacent walls
	for _,a := range A { b := (a+1)/2; if b <= s1 { s1,s2 = b,s1 } else if b <= s2 { s2 = b } }
	best = s1+s2
	// Possibility 2, we shoot down two adjacent walls
	solvepair := func(a,b int64) int64 {
		if a < b { a,b = b,a }
		ans := (a+1)/2;
		if b > ans {
			ans = a-b; a -= 2*ans; b-= ans
			tt := a/3; ans += 2*tt; a -= 3*tt
			if a == 1 { ans++ } else if a == 2 { ans += 2 }
		}
		//fmt.Fprintf(wrtr,"DBG: solvepair:(%v,%v) = %v\n",a,b,ans)
		return ans
	}
	//fmt.Fprintf(wrtr,"DBG: best before solvepair:%v\n",best)
	for i:=I(0);i+1<N;i++ { cand := solvepair(A[i],A[i+1]); best = min(best,cand) }
	fmt.Fprintln(wrtr,best)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func I(a int) int64 { return int64(a) }
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gi2() (int64,int64) { return gi(),gi() }
func gi3() (int64,int64,int64) { return gi(),gi(),gi() }
func gi4() (int64,int64,int64,int64) { return gi(),gi(),gi(),gi() }
func gis(n int64) []int64 { res := make([]int64,n); for i:=I(0);i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int64) []float64  { res := make([]float64,n); for i:=I(0);i<n;i++ { res[i] = gf() }; return res }
func gss(n int64) []string  { res := make([]string,n); for i:=I(0);i<n;i++ { res[i] = gs() }; return res }
func ia(m int64) []int64 { return make([]int64,m) }
func iai(m int64,v int64) []int64 { a := make([]int64,m); for i:=I(0);i<m;i++ { a[i] = v }; return a }
func twodi(n int64,m int64,v int64) [][]int64 {
	r := make([][]int64,n); for i:=I(0);i<n;i++ { x := make([]int64,m); for j:=I(0);j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int64) ([]int64,[]int64) { a,b := ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int64) ([]int64,[]int64,[]int64) { a,b,c := ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int64) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int64) int64 { if a < 0 { return -a }; return a }
func rev(a []int64) { i,j := I(0),I(len(a)-1); for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int64) int64 { if a > b { return a }; return b }
func min(a,b int64) int64 { if a > b { return b }; return a }
func tern(cond bool, a int64, b int64) int64 { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int64) int64 { ans := I(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int64) { for i:=I(0); i<I(len(a)); i++ { a[i] = 0 } }
func powmod(a,e,mod int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int64) (int64,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=I(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
const inf int64 = 1000000000000000000
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	//N := gi(); A := gis(N)
	N := I(3); A := []int64{1,8,1}
	best,s1,s2 := inf,inf,inf
	// Possibility 1, we shoot down two non-adjacent walls
	for _,a := range A { b := (a+1)/2; if b <= s1 { s1,s2 = b,s1 } else if b <= s2 { s2 = b } }
	best = s1+s2
	// Possibility 2, we shoot down two adjacent walls
	solvepair := func(a,b int64) int64 {
		if a < b { a,b = b,a }
		ans := (a+1)/2;
		if b > ans {
			ans = a-b; a -= 2*ans; b-= ans
			tt := a/3; ans += 2*tt; a -= 3*tt
			if a == 1 { ans++ } else if a == 2 { ans += 2 }
		}
		fmt.Fprintf(wrtr,"DBG: solvepair:(%v,%v) = %v\n",a,b,ans)
		return ans
	}
	fmt.Fprintf(wrtr,"DBG: best before solvepair:%v\n",best)
	for i:=I(0);i+1<N;i++ { cand := solvepair(A[i],A[i+1]); best = min(best,cand) }
	fmt.Fprintln(wrtr,best)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func I(a int) int64 { return int64(a) }
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gi2() (int64,int64) { return gi(),gi() }
func gi3() (int64,int64,int64) { return gi(),gi(),gi() }
func gi4() (int64,int64,int64,int64) { return gi(),gi(),gi(),gi() }
func gis(n int64) []int64 { res := make([]int64,n); for i:=I(0);i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int64) []float64  { res := make([]float64,n); for i:=I(0);i<n;i++ { res[i] = gf() }; return res }
func gss(n int64) []string  { res := make([]string,n); for i:=I(0);i<n;i++ { res[i] = gs() }; return res }
func ia(m int64) []int64 { return make([]int64,m) }
func iai(m int64,v int64) []int64 { a := make([]int64,m); for i:=I(0);i<m;i++ { a[i] = v }; return a }
func twodi(n int64,m int64,v int64) [][]int64 {
	r := make([][]int64,n); for i:=I(0);i<n;i++ { x := make([]int64,m); for j:=I(0);j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int64) ([]int64,[]int64) { a,b := ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int64) ([]int64,[]int64,[]int64) { a,b,c := ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int64) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=I(0);i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int64) int64 { if a < 0 { return -a }; return a }
func rev(a []int64) { i,j := I(0),I(len(a)-1); for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int64) int64 { if a > b { return a }; return b }
func min(a,b int64) int64 { if a > b { return b }; return a }
func tern(cond bool, a int64, b int64) int64 { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int64) int64 { ans := I(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int64) { for i:=I(0); i<I(len(a)); i++ { a[i] = 0 } }
func powmod(a,e,mod int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int64) int64 { res, m := I(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int64) (int64,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int64,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=I(1);i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
const inf int64 = 1000000000000000000
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); A := gis(N)
	best,s1,s2 := inf,inf,inf
	// Possibility 1, we shoot down two non-adjacent walls
	for _,a := range A { b := (a+1)/2; if b <= s1 { s1,s2 = b,s1 } else if b <= s2 { s2 = b } }
	best = s1+s2
	// Possibility 2, we shoot down two adjacent walls
	solvepair := func(a,b int64) int64 {
		if a < b { a,b = b,a }
		s1 := (a+1)/2; if b <= s1 { return s1 }
		s2 := a-b; a -= 2*s2; b-= s2
		tt := a/3; s2 += 2*tt; a -= 3*tt
		if a == 1 { s2++ } else if a == 2 { s2 += 2 }
		return s2
	}
	for i:=I(0);i+1<N;i++ { cand := solvepair(A[i],A[i+1]); best = min(best,cand) }
	fmt.Println(best)
}

package main

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

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

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

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

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

	arr := make([]int, n)
	m1, m2 := math.MaxInt32, math.MaxInt32
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])

		if m1 > arr[i] {
			m1, m2 = arr[i], m1
		} else if m2 > arr[i] {
			m2 = arr[i]
		}
	}

	ans := (m1+1)/2 + (m2+1)/2
	for i := 0; i < n-2; i++ {
		ans = min(ans, (arr[i]+arr[i+2]+1)/2)
	}
	for i := 1; i < n-1; i++ {
		ans = min(ans, max((arr[i]+1)/2, (arr[i+1]+1)/2, (arr[i]+arr[i+1]+2)/3))
	}

	fmt.Fprintln(out, ans)
}

package main

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

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

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

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

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

	arr := make([]int, n)
	m1, m2 := math.MaxInt32, math.MaxInt32
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])

		if m1 > arr[i] {
			m1, m2 = arr[i], m1
		} else if m2 > arr[i] {
			m2 = arr[i]
		}
	}

	ans := (m1+1)/2 + (m2+1)/2
	for i := 0; i < n-2; i++ {
		ans = min(ans, (arr[i]+arr[i+2])/2)
	}
	for i := 1; i < n-1; i++ {
		ans = min(ans, max((arr[i]+1)/2, (arr[i+1]+1)/2, (arr[i]+arr[i+1]+2)/3))
	}

	fmt.Fprintln(out, ans)
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func getAns(a int, b int) int {
	ans := 100_000_000

	l, r := 0, 100_000

	count := func(k1 int) int {
		ak2 := a - k1*2
		bk2 := (b-k1)/2 + (b-k1)%2
		k2 := max(max(ak2, bk2), 0)
		return k1 + k2
	}

	for r-l > 5 {
		x1 := l + (r-l)/3
		x2 := r - (r-l)/3

		if count(x1) < count(x2) {
			r = x2
		} else {
			l = x1
		}
	}

	for i := l; i <= r; i++ {
		ans = min(ans, count(i))
	}

	return ans
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	n := io.ReadInt()
	a := io.ReadIntSlice(n)

	ans := 100_000_000

	for i := 1; i < len(a)-1; i++ {
		mx := max(a[i-1], a[i+1])
		mn := min(a[i-1], a[i+1])
		dop := (mx-mn)/2 + (mx-mn)%2
		ans = min(ans, mn+dop)
	}

	for i := 0; i < len(a)-1; i++ {
		ans = min(ans, getAns(a[i], a[i+1]))
	}

	sort.Ints(a)
	ans = min(ans, a[0]/2+a[0]%2+a[1]/2+a[1]%2)

	fmt.Println(ans)
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func getAns(a int, b int) int {
	ans := 100_000_000

	l, r := 0, 100_000

	count := func(k1 int) int {
		ak2 := a - k1*2
		bk2 := (b-k1)/2 + (b-k1)%2
		k2 := max(max(ak2, bk2), 0)
		return k1 + k2
	}

	for r-l > 5 {
		x1 := l + (r-l)/3
		x2 := r - (r-l)/3

		if count(x1) < count(x2) {
			r = x2
		} else {
			l = x1
		}
	}

	for i := l; i <= r; i++ {
		ans = min(ans, count(i))
	}

	return ans
}

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	n := io.ReadInt()
	a := io.ReadIntSlice(n)

	ans := 100_000_000

	for i := 1; i < len(a)-1; i++ {
		ans = min(ans, max(a[i-1], a[i+1]))
	}

	for i := 0; i < len(a)-1; i++ {
		ans = min(ans, getAns(a[i], a[i+1]))
	}

	sort.Ints(a)
	ans = min(ans, a[0]/2+a[0]%2+a[1]/2+a[1]%2)

	fmt.Println(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1674E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	fi, se := int(1e9), int(1e9)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] < fi {
			fi, se = a[i], fi
		} else if a[i] < se {
			se = a[i]
		}
	}
	ans := (fi+1)/2 + (se+1)/2
	for i := 1; i < n; i++ {
		v, w := a[i-1], a[i]
		if i < n-1 {
			ans = min(ans, max(v, a[i+1]))
		}
		if v < w {
			v, w = w, v
		}
		if v >= w*2 {
			ans = min(ans, (v+1)/2)
		} else {
			d := v - w
			w -= d
			ans = min(ans, d+w/3*2+w%3)
		}
	}
	Fprint(out, ans)
}

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

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


Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.  To reach the goal, Egor should research the next topic:There is an $$$N \times N$$$ board. Each cell of the board has a number from $$$1$$$ to $$$N ^ 2$$$ in it and numbers in all cells are distinct.In the beginning, some chess figure stands in the cell with the number $$$1$$$. Note that this cell is already considered as visited. After that every move is determined by the following rules:   Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of $$$1$$$ vun. If all cells are already visited, the process is stopped. Egor should find an $$$N \times N$$$ board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such $$$N \times N$$$ numbered board, or tell that it doesn't exist.

The only line contains one integer $$$N$$$  — the size of the board, $$$1\le N \le 500$$$.

The output should contain $$$N$$$ lines. In $$$i$$$-th line output $$$N$$$ numbers  — numbers on the $$$i$$$-th row of the board. All numbers from $$$1$$$ to $$$N \times N$$$ must be used exactly once. On your board rook must pay strictly less vuns than the queen. If there are no solutions, print $$$-1$$$. If there are several solutions, you can output any of them.

NoteIn case we have $$$1 \times 1$$$ board, both rook and queen do not have a chance to pay fees.In second sample rook goes through cells $$$1 \to 3 \to 4 \to 6 \to 9 \to 5 \to 7 \to 13 \to 2 \to 8 \to 16 \to 11 \to 10 \to 12 \to 15 \to \textbf{(1 vun)} \to 14$$$. Queen goes through $$$1 \to 3 \to 4 \to 2 \to 5 \to 6 \to 9 \to 7 \to 13 \to 8 \to 11 \to 10 \to 12 \to 15 \to \textbf{(1 vun)} \to 14 \to \textbf{(1 vun)} \to 16$$$.As a result rook pays 1 vun and queen pays 2 vuns.

package main

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

func main() {

	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var A [][]int
	var n, i, j, k int
	fmt.Fscanf(rd, "%d\n", &n)
	if n < 3 {
		fmt.Fprintf(wr, "-1\n")
	} else if n == 3 {
		fmt.Fprintf(wr, "1 7 9 \n3 2 5 \n4 8 6 \n")
	} else {
		A = make([][]int, n)
		for i = 0; i < n; i++ {
			A[i] = make([]int, n)
			if (i+n)%2 == 0 {
				for j = 0; j < n; j++ {
					if i == 1 && i+j == n-1 {
						A[i][j] = n*n - 2
						continue
					}
					if i == 1 && i+j == n-2 {
						A[i][j] = n*n - 1
						continue
					}
					if i == n-1 && j == n-2 {
						A[i][j] = n * n
						continue
					}
					k++
					A[i][j] = k
				}
			} else {
				for j = n - 1; j >= 0; j-- {
					if i == 1 && i+j == n-1 {
						A[i][j] = n*n - 2
						continue
					}
					if i == 1 && i+j == n-2 {
						A[i][j] = n*n - 1
						continue
					}
					if i == n-1 && j == n-2 {
						A[i][j] = n * n
						continue
					}
					k++
					A[i][j] = k
				}
			}
		}
		for i = 0; i < n; i++ {
			for j = 0; j < n; j++ {
				fmt.Fprintf(wr, "%d ", A[i][j])
			}
			fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}

package main

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

func main() {

	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var A [][]int
	var n, i, j, k int
	fmt.Fscanf(rd, "%d\n", &n)
	if n < 4 {
		fmt.Fprintf(wr, "-1\n")
	} else {
		A = make([][]int, n)
		for i = 0; i < n; i++ {
			A[i] = make([]int, n)
			if (i+n)%2 == 0 {
				for j = 0; j < n; j++ {
					if i == 1 && i+j == n-1 {
						A[i][j] = n*n - 2
						continue
					}
					if i == 1 && i+j == n-2 {
						A[i][j] = n*n - 1
						continue
					}
					if i == n-1 && j == n-2 {
						A[i][j] = n * n
						continue
					}
					k++
					A[i][j] = k
				}
			} else {
				for j = n - 1; j >= 0; j-- {
					if i == 1 && i+j == n-1 {
						A[i][j] = n*n - 2
						continue
					}
					if i == 1 && i+j == n-2 {
						A[i][j] = n*n - 1
						continue
					}
					if i == n-1 && j == n-2 {
						A[i][j] = n * n
						continue
					}
					k++
					A[i][j] = k
				}
			}
		}
		for i = 0; i < n; i++ {
			for j = 0; j < n; j++ {
				fmt.Fprintf(wr, "%d ", A[i][j])
			}
			fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}

package main

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

func main() {

	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var A [][]int
	var n, i, j, k int
	fmt.Fscanf(rd, "%d\n", &n)
	if n < 4 {
		fmt.Fprintf(wr, "-1\n")
	} else {
		A = make([][]int, n)
		for i = 0; i < n; i++ {
			A[i] = make([]int, n)
			if (i+n)%2 == 0 {
				for j = n - 2; j >= 0; j-- {
					k++
					A[i][j] = k
				}
			} else {
				if i == n-1 {
					for j = 0; j < n-2; j++ {
						k++
						A[i][j] = k
					}
					for j = 0; j < n; j++ {
						k++
						A[j][n-1] = k
					}
					k++
					A[n-1][n-2] = k
				} else {
					for j = 0; j <= n-2; j++ {
						k++
						A[i][j] = k
					}
				}
			}
		}
		for i = 0; i < n; i++ {
			for j = 0; j < n; j++ {
				fmt.Fprintf(wr, "%d ", A[i][j])
			}
			fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}

package main

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

func main() {

	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var A [][]int
	var n, i, j, k int
	fmt.Fscanf(rd, "%d\n", &n)
	if n < 4 {
		fmt.Fprintf(wr, "-1\n")
	} else {
		A = make([][]int, n)
		for i = 0; i < n; i++ {
			A[i] = make([]int, n)
			if (i+n)%2 == 0 {
				for j = n - 2; j >= 0; j-- {
					k++
					A[i][j] = k
				}
			} else {
				if i == n-1 {
					for j = 0; j < n-2; j++ {
						k++
						A[i][j] = k
					}
					k++
					A[n-3][n-1] = k
					k++
					A[n-2][n-1] = k
					k++
					A[n-1][n-1] = k
					k++
					A[n-1][n-2] = k
					for j = n - 4; j >= 0; j-- {
						k++
						A[j][n-1] = k
					}
				} else {
					for j = 0; j <= n-2; j++ {
						k++
						A[i][j] = k
					}
				}
			}
		}
		for i = 0; i < n; i++ {
			for j = 0; j < n; j++ {
				fmt.Fprintf(wr, "%d ", A[i][j])
			}
			fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}