Thanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?*Infinity Gauntlet required.

The first line of input contains a single number $$$n$$$ ($$$1 \le n \le 16$$$) — the size of the array. $$$n$$$ is guaranteed to be a power of 2. The second line of input contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 100$$$) — the elements of the array.

Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.

NoteIn the first example the array is already sorted, so no finger snaps are required.In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.

package main

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

var res []int
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func max(array []int) {
	var max int = array[0]
	for _, value := range array {
		if max < value {
			max = value
		}
	}
	printf("%d", max)
}

func checkSort( size int, inputArray []int) {
	for i:=0; i<size-1;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			checkSort(size, inputArray)
			checkSort(size, inputArray[size:])
			return
		}
	}
	res = append(res, size)
}

func main() {
	defer writer.Flush()
	var size int

	fmt.Scan(&size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	checkSort(size, inputArray)
	max(res)

}

package main

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

func main() {
	inputreader := bufio.NewReader(os.Stdin)
	var str string
	str,_= inputreader.ReadString('\n')
	str=strings.TrimSpace(str)
	temp:=strings.Split(str," ")
	N,_:= strconv.Atoi(temp[0])
	arr:=make([]int,N)
	str,_= inputreader.ReadString('\n')
	str=strings.TrimSpace(str)
	temp=strings.Split(str," ")
	for i:=0;i<N;i++{
		arr[i],_= strconv.Atoi(temp[i])
	}

fmt.Println(isSorted(arr,0,N-1))

}
func isSorted(arr[]int,start,end int)int{
	if end==start{
		return 1
	}
	check:=true
	for i:=start;i<end;i++{
		if arr[i]>arr[i+1]{
			check=false
			break
		}
	}
  if check{
  	return end-start+1
  }
	mid:=(start+end)/2
	return max(isSorted(arr,start,mid),isSorted(arr,mid+1,end))

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

package main

import (
	"fmt"
	"sort"
)

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

func dfs(s []int) int {
	// fmt.Println("[d01] dfs en: s", s)
	ok := true
	if len(s) == 1 {
		return len(s)
	}
	t := make([]int, len(s))
	copy(t, s)
	sort.Ints(t)
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			ok = false
			break
		}
	}
	if ok {
		return len(s)
	}
	return max(dfs(s[:len(s)/2]), dfs(s[len(s)/2:]))
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	// fmt.Println("n", n, "a", a)
	fmt.Println(dfs(a))
}

package main

import "fmt"

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

func sorted(arr []int) bool {
	for i := 1; i < len(arr); i++ {
		if arr[i-1] > arr[i] {
			return false
		}
	}
	return true
}

func thanos(arr []int) int {
	if sorted(arr) {
		return len(arr)
	}

	return max(thanos(arr[:len(arr)/2]), thanos(arr[len(arr)/2:]))
}

func main() {
	var n int
	var arr []int

	fmt.Scanf("%d\n", &n)
	arr = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	fmt.Println(thanos(arr))
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)
	last := 0
	min := 0
	high := int(math.Log2(float64(n))) + 1

	var states = make([]bool, high)

	for i := 0; i < n; i++ {
		var cur int
		_, _ = fmt.Scanf("%d", &cur)

		if last == 0 {
			last = cur
			continue
		}

		for j:= min; j < high; j++ {
			q := 1 << uint(j)
			if i % q == 0 {

				if ! states[j] {
					min = j
				}
				states[j] = false

			} else {
				states[j] = states[j] || last > cur
			}
		}

		last = cur
	}

	for j:= min; j < high; j++ {
		if ! states[j] {
			min = j
		}
	}

	fmt.Print(1 << uint(min))
}

package main

import "fmt"

func main(){
	//获取输入参数
	var n int
	var arr []int
	fmt.Scanln(&n)

	for i := 1; i <= n; i++{
		var num int
		if(i != n){
			fmt.Scanf("%d", &num)
		} else {
			fmt.Scanln(&num)
		}
		arr = append(arr, num)
	}

	size := getSize(0, n - 1, arr)
	fmt.Println(size)
}

func getSize(begin int, end int, arr []int) int {
	if beOrder(begin, end, arr) {
		return end - begin + 1
	} else if begin < end - 1 {
		half := (end - begin) / 2 + begin
		sub1 := getSize(begin, half, arr)
		sub2 := getSize(half + 1, end, arr)
		if sub1 > sub2 {
			return sub1
		} else {
			return sub2
		}
	} else {
		return 1
	}

}

//判断是否有序
func beOrder(begin int, end int, arr []int) bool {
	if(begin >= end) {
		return true
	}
	for i := begin + 1; i <= end; i++ {
		if arr[i] < arr[i - 1] {
			return false
		}
	}
	return true
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"sort"
	"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

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
}

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

func gcdll(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcdll(b, a%b)
}

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

	n := readi()
	a := make([]int, n)
	for i := range a {
		a[i] = readi()
	}
	println(dfs(a, 0, n))
}

func dfs(a []int, l, r int) int {
	if sort.IsSorted(sort.IntSlice(a[l:r])) {
		return r - l
	}
	m := (l + r) / 2
	return max(dfs(a, l, m), dfs(a, m, r))
}

package main

import "fmt"

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

func f(a []int, start int, end int) int {
	ok := true
	for i := start; i <= end-1; i++ {
		if a[i] > a[i+1] {
			ok = false
			break
		}
	}
	if ok {
		return end - start + 1
	} else {
		mid := (start + end) / 2
		return Max(f(a, start, mid), f(a, mid+1, end))
	}
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(f(a, 0, n-1))
}

package main

import (
        "fmt"
        "sort"
)

var num int

func main() {
        fmt.Scanln(&num)
        a := make([]int, num)
        for i := 0; i < num; i++ {
                fmt.Scan(&a[i])
        }
        for i := num; i >= 1; i /= 2 {
                for j := 0; j < num; j += i {
                        if sort.IntsAreSorted(a[j : j+i]) {
                                fmt.Println(i)
                                return
                        }
                }
        }
}

package main

import (
	"fmt"
	"sort"
)

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

	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	for partSize := n; partSize >= 1; partSize /= 2 {
		for seqStart := 0; seqStart < n; seqStart += partSize {
			if sort.IntsAreSorted(a[seqStart:seqStart + partSize]) {
				fmt.Println(partSize)
				return
			}
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	input := make([]string, 0)
	for scanner.Scan() {
		input = append(input, scanner.Text())
	}
	n, err := strconv.Atoi(input[0])
	if err != nil {
		log.Fatal(err)
	}
	arrayStrings := strings.Split(input[1], " ")
	array := make([]int, n)
	for index, item := range arrayStrings {
		array[index], _ = strconv.Atoi(item)
	}
	fmt.Println(getSortedLen(array))
}

func getSortedLen(array []int) int {
	if sort.SliceIsSorted(array, func(p, q int) bool {
		return array[p] < array[q]
	}) {
		return len(array)
	}
	left := getSortedLen(array[:len(array)/2])
	right := getSortedLen(array[len(array)/2:])
	if left > right {
		return left
	}
	return right
}

package main

import (
	"fmt"
)

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

func solve( tmp []int) int{
	l := len(tmp)

	if l <= 1{
		return 1
	}

	if l == tmp[l-1]-tmp[0]+1{
		return l
	}
	return max(solve(tmp[0:l/2]), solve(tmp[l/2:]))
}

func main(){
	n := 0
	fmt.Scan(&n)
	arr := make([]int, n)
	tmp := make([]int, n)

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

	if n == 0 || n == 1{
		fmt.Println(n)
		return
	}

	for i:=0; i < n; i++{
		tmp[i] = 1
		if i != 0 && arr[i-1] <= arr[i]{
			tmp[i] = tmp[i-1] + tmp[i]
		}
	}
	// for i, val :=range tmp{
	//  	fmt.Printf("%d ----> %d\n", i, val)
	//  }
	fmt.Println(solve(tmp[0:]))
}

package main

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

func main() {

	scan := bufio.NewScanner(os.Stdin)

	scan.Scan()
	scan.Text()

	scan.Scan()
	txt := strings.Fields(scan.Text())

	var nums []int

	for _, v := range txt {

		sc, _ := strconv.Atoi(v)
		nums = append(nums, sc)
	}

	for i := 1; i < len(nums); i++ {

		if nums[i-1] > nums[i] {

			if cut := len(nums) / 2; i-1 < cut {
				nums = append(nums[cut:])
			} else {
				nums = append(nums[:cut])
			}
			i = 0
		}
	}

	fmt.Print(len(nums))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	arr := make([]int, n)

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

	c, _ := thanosCount(arr, 0, n-1)
	fmt.Println(c)
}

func thanosCount(a []int, l, r int) (int, bool) {
	if r == l {
		return 1, true
	}
	if r == l+1 {
		if a[l] <= a[r] {
			return 2, true
		} else {
			return 1, false
		}
	}

	mid := (l + r) / 2

	lc, lb := thanosCount(a, l, mid)
	rc, rb := thanosCount(a, mid+1, r)

	if lb && rb && a[mid] <= a[mid+1] {
		return lc + rc, true
	}
	if lc > rc {
		return lc, false
	} else {
		return rc, false
	}
}

package main

import "fmt"

func main() {
	var sliceLen int
	slice := make([]int, 0, 100)
	var tmp int

	fmt.Scanf("%d\r", &sliceLen)
	for i := 0; i < sliceLen; i++ {
		fmt.Scanf("%d", &tmp)
		slice = append(slice, tmp)
	}

	fmt.Println(thanosSort(sliceLen, slice))
}

func thanosSort(sliceLen int, slice []int) int {
	if sliceLen == 1 {
		return 1
	}

	if isSorted(sliceLen, slice) {
		return sliceLen
	}

	newSliceLen := sliceLen / 2
	sortLenLeft := thanosSort(newSliceLen, slice[:newSliceLen])
	sortLenRight := thanosSort(newSliceLen, slice[newSliceLen:])

	if sortLenLeft > sortLenRight {
		return sortLenLeft
	}
	return sortLenRight

}

func isSorted(n int, slice []int) bool {
	for i := 1; i < n; i++ {
		if slice[i] < slice[i-1] {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}
var lent =0
func thanos (arr []int){
	if isSorted(arr){
		if len(arr)>lent{
			lent=len(arr)
		}
		return
	}
	left:=arr[:(len(arr)/2)]
	right:=arr[(len(arr)/2):]
		thanos(left)
	thanos(right)
}
func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	thanos(arr)
	fmt.Println(lent)

}

package main

import (
	"fmt"
)

func main() {

	var length int
	fmt.Scanf("%d", &length)

	numbers := make([]int, length)

	for i := range numbers {
		fmt.Scan(&numbers[i])
	}

	fmt.Print(thanos(numbers))
}

func thanos(numbers []int) int {
	if checkSort(numbers) {
		return len(numbers)
	}

	return max(
		thanos(numbers[:(len(numbers) / 2)]),
		thanos(numbers[(len(numbers) / 2):]),
	)
}

func checkSort(numbers []int) bool {
	if len(numbers) <= 1 {
		return true
	}

	for i := 1; i < len(numbers); i++ {
		if numbers[i] < numbers[i-1] {
			return false
		}
	}

	return true
}

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

	return a
}

package main

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

func thanos(arr[] int64) int {
	length := len(arr)
	possible := 1
	flag := true
	i :=0
	for ; i < length-1; i++ {
		if arr[i] > arr[i+1] {
			flag = false
			break
		}
		possible++
	}
	if flag == true {
		return possible
	} else {
		return int(math.Max(float64(thanos(arr[0: (length/2)])), float64(thanos(arr[(length/2): length]))))
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	length, err := strconv.ParseInt(string(line[0:]), 10, 0)
	if err != nil {
		fmt.Printf("err %v", err)
	}
	data := make([]int64, length)
	x, _, _ := reader.ReadLine()
	x1 := strings.Split(string(x[0:]), " ")
	for i := 0; i < int(length); i++ {
		data[i], _ = strconv.ParseInt(x1[i], 10, 0)
	}
	n := thanos(data)
	fmt.Printf("%d", n)

}

package main

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

var a [16]int

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n - 1;i ++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	fmt.Fscanf(reader, "%d", &a[n - 1])
	for i := n;i > 0; i = i >> 1 {
		for j := 0;j < n;j += i {
			inc := true
			for k := j;k < j + i - 1;k ++ {
				if a[k] > a[k + 1] {
					inc = false
				}
			}
			if inc {
				fmt.Printf("%d", i)
				return
			}
		}
	}
}

package main

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

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

func thanosSort(nums []int, i int, j int) int {
	if i >= j {
		return 1
	}
	curMax := 1
	for ii := i; ii < j; ii++ {
		if nums[ii] > nums[ii+1] {
			curMax = 0
			break
		}
		curMax++
	}
	mid := i + (j-i)/2
	leftMax := thanosSort(nums, i, mid)
	rightMax := thanosSort(nums, mid+1, j)
	return max(curMax, max(leftMax, rightMax))
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	size, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	nums := scanner.Text()
	numsSlice := strings.Split(nums, " ")
	var numbers []int
	for _, v := range numsSlice {
		val, _ := strconv.Atoi(v)
		numbers = append(numbers, val)
	}
	if size == 0 || size == 1 {
		fmt.Println(1)
		return
	}
	fmt.Println(thanosSort(numbers, 0, size-1))
}

package main

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

var ans = 1

func main() {
	var n int
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	_, _ = fmt.Sscanf(scanner.Text(), "%d", &n)
	mySlice := make([]int, n)
	scanner.Scan()
	numbersAsString := strings.Split(scanner.Text(), " ")
	for i, v := range numbersAsString {
		mySlice[i], _ = strconv.Atoi(v)
	}
	checkSlice(mySlice)
	fmt.Println(ans)
}

func checkSlice(mySlice []int) {
	if checkIsSorted(mySlice) {
		if len(mySlice) > ans {
			ans = len(mySlice)
		}
	} else {
		firstHalf := mySlice[:len(mySlice)/2]
		//fmt.Println("checking : ", firstHalf)
		checkSlice(firstHalf)
		secondHalf := mySlice[len(mySlice)/2:]
		//fmt.Println("checking 2 : ", secondHalf)
		checkSlice(secondHalf)
	}
}
func checkIsSorted(numbers []int) bool {
	result := true
	for i, v := range numbers {
		if i != len(numbers)-1 {
			if v > numbers[i+1] {
				result = false
			}
		}
	}
	return result
}

package main

import (
	"fmt"
)

func sort(size int, arr []int) int {

	if size > 2 {
		half := size / 2
		left_half := sort(half, arr[:half])
		right_half := sort(half, arr[half:])
		if left_half == half && right_half == half && arr[half-1] <= arr[half] {
			return right_half + left_half

		} else if left_half == 1 && right_half == 1 {
			return 1
		} else if left_half < right_half {
			return right_half
		} else if left_half > right_half {
			return left_half
		} else {
			return right_half
		}

	} else {

		if arr[0] <= arr[1] {
			return 2
		} else {
			return 1
		}
	}

}

func main() {

	var n int
	fmt.Scanf("%d\n", &n)
	inputdata := make([]int, n)
	for i, _ := range inputdata {
		fmt.Scanf("%d", &inputdata[i])
	}

	if n <= 1 {
		fmt.Println(n)
	} else {
		fmt.Println(sort(n, inputdata))
	}

}

package main

import (
. "fmt"
)

const MAXN = 20
var arr [MAXN]int

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

func maks(l int, r int) int {
    gagal := false
    for i := l+1; i <= r; i++ {
        if arr[i-1] > arr[i] {
            gagal = true
        }
    }
    if !gagal {
        return r-l+1
    } else {
        return Max(maks(l, (l+r)/2), maks((l+r)/2+1, r))
    }
}

func main() {
    var N int
    Scan(&N)

    for i := 0; i < N; i++ {
        Scan(&arr[i])
    }
    Println(maks(0, N-1))
}

package main

import "fmt"

func isSorted(arr []int) bool {
	for i := 1; i < len(arr); i++ {
		if arr[i] < arr[i-1] {
			return false
		}
	}
	return true
}

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

func GetMaxSortedArrLength(arr []int) int {
	if len(arr) <= 1 {
		return len(arr)
	}

	if isSorted(arr) {
		return len(arr)
	}

	return max(GetMaxSortedArrLength(arr[0:len(arr)/2]),
		GetMaxSortedArrLength(arr[len(arr)/2:len(arr)]))
}

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

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	// arr := []int{11, 12, 1, 2, 13, 14, 3, 4}
	res := GetMaxSortedArrLength(arr)
	fmt.Println(res)
}

package main

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

var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func checkSort(begin int, size int, inputArray []int) int {
	for i:=0; i<size-1;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			checkSort(0, size/2, inputArray)
			checkSort( size/2,size, inputArray)
		}
	}
	return size
}

func main() {
	defer writer.Flush()
	var size int

	fmt.Scan(&size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	size = checkSort(0,size, inputArray)
	printf("%d", size)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var size int

	scanf("%d", &size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	for i:=0; i<size-2;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			i = 0
		}
	}
	printf("%d", size)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func main() {
	defer writer.Flush()
	var size int

	fmt.Scan(&size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	for i:=0; i<size-1;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			i = 0
		}
	}
	if inputArray[0] > inputArray[size-1] {
		size /=2
	}
	printf("%d", size)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func main() {
	defer writer.Flush()
	var size int

	fmt.Scan(&size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	for i:=0; i<size-2;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			i = 0
		}
	}
	printf("%d", size)
}

package main

import "fmt"

func main()  {
	var size int
	var j int
	fmt.Scanln(&size)

	slice := make([]int, 0)
	for i:=0;i<size; i++ {
		fmt.Scanln(&j)
		slice = append(slice, j)
	}
	for i:=0;i<size-2;i++{
		if slice[i] > slice[i+1]{
			size /= 2
			i = 0
		}
	}
	fmt.Println(size)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var size int

	scanf("%d", &size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	for i:=0; i<size-2;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			i = 0
		}
	}
	println(size)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	var size int

	scanf("%d", &size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	for i:=0; i<size-2;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			i = 0
		}
	}
	//
	printf("%d", size)
}

package main

import "fmt"

func min(arr []int) int {
	res := arr[0]
	for i := 1; i < len(arr); i++ {
		if arr[i] < res {
			res = arr[i]
		}
	}
	return res
}

func thanos(arr []int) int {
	for n := len(arr); n > 0; n /= 2 {
		small := 0
		step := len(arr) / n
		var i = 0

		for i = 0; i < len(arr); i += step {
			if min(arr[i:i+step]) < small {
				break
			}
			small = min(arr[i : i+step])
		}

		if i >= len(arr) {
			return n
		}
	}

	return 1
}

func main() {
	var n int
	var arr []int

	fmt.Scanf("%d", &n)
	arr = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	fmt.Println(thanos(arr))
}

package main

import "fmt"

func min(arr []int) int {
	res := arr[0]
	for i := 1; i < len(arr); i++ {
		if arr[i] < res {
			res = arr[i]
		}
	}
	return res
}

func thanos(arr []int) int {
	for n := len(arr); n > 0; n /= 2 {
		small := 0
		step := len(arr) / n
		var i = 0

		for i = 0; i < len(arr); i += step {
			if min(arr[i:i+step]) < small {
				break
			}
			small = min(arr[i : i+step])
		}

		if i >= len(arr) {
			return n
		}
	}

	return 1
}

func main() {
	var n int
	var arr []int

	fmt.Scanf("%d\n", &n)
	arr = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	fmt.Println(thanos(arr))
}

package main

import "fmt"

const inf = 101

func min(small int, arr []int) int {
	res := inf
	for i := 0; i < len(arr); i++ {
		if arr[i] < res && arr[i] >= small {
			res = arr[i]
		}
	}

	if res == inf {
		return -1
	}
	return res
}

func thanos(arr []int) int {
	for n := len(arr); n > 0; n /= 2 {
		small := 0
		step := len(arr) / n
		var i = 0

		for i = 0; i < len(arr); i += step {
			newSmall := min(small, arr[i:i+step])
			if newSmall < small {
				break
			}
			small = newSmall
		}

		if i >= len(arr) {
			return n
		}
	}

	return 1
}

func main() {
	var n int
	var arr []int

	fmt.Scanf("%d\n", &n)
	arr = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	fmt.Println(thanos(arr))
}

package main

import (
	"flag"
	"fmt"
	"math"
	"os"
)

var inHandle *os.File

var quads = []int{
	0,
	1,
	2,
	4,
	8,
	16,
	32,
	64,
	128,
	256,
	512,
	1024,
	2048,
	4096,
	8192,
	16384,
	32768,
	65536,
}

func main() {
	initialize()

	n := readInt()
	last := 0
	min := 1
	high := int(math.Log2(float64(n))) + 1

	var states [17]bool

	for i := 0; i < n; i++ {
		cur := readInt()
		if last == 0 {
			last = cur
			continue
		}

		for j:= min; j < high; j++ {
			q := quads[j]
			if i % q == 0 {

				if ! states[j] {
					min = j
				}
				states[j] = false

			} else {
				states[j] = states[j] || last > cur
			}
		}

		last = cur
	}

	for j:= min; j < high; j++ {
		if ! states[j] {
			min = j
		}
	}

	fmt.Print(quads[min])
}

func initialize() {
	fileName := flag.String("in", "", "")
	flag.Parse()

	if "" == *fileName {
		inHandle = os.Stdin
	} else {
		var err error
		inHandle, err = os.Open(*fileName)
		if err != nil {
			panic(err)
		}
	}
}

func readInt() int {
	var i int
	_, _ = fmt.Fscanf(inHandle, "%d", &i)
	return i
}

package main

import (
	"flag"
	"fmt"
	"math"
	"os"
)

var inHandle *os.File

var quads = []int{
	0,
	1,
	2,
	4,
	8,
	16,
	32,
	64,
	128,
	256,
	512,
	1024,
	2048,
	4096,
	8192,
	16384,
	32768,
	65536,
}

func main() {
	initialize()

	n := readInt()
	last := 0
	min := 1
	high := int(math.Log2(float64(n))) + 1

	var states [17]bool

	for i := 0; i < n; i++ {
		cur := readInt()
		if last == 0 {
			last = cur
			continue
		}

		for j:= min; j <= high; j++ {
			q := quads[j]
			if i % q == 0 {

				if ! states[j] {
					min = j
				}
				states[j] = false

			} else {
				states[j] = states[j] || last > cur
			}
		}

		last = cur
	}

	for j:= min; j <= high; j++ {
		if ! states[j] {
			min = j
		}
	}

	fmt.Print(quads[min])
}

func initialize() {
	fileName := flag.String("in", "", "")
	flag.Parse()

	if "" == *fileName {
		inHandle = os.Stdin
	} else {
		var err error
		inHandle, err = os.Open(*fileName)
		if err != nil {
			panic(err)
		}
	}
}

func readInt() int {
	var i int
	_, _ = fmt.Fscanf(inHandle, "%d", &i)
	return i
}

package main

import (
	"flag"
	"fmt"
	"math"
	"os"
)

func main() {
	initialize()

	n := readInt()
	v := make([]int, n)

	for i := 0; i < n; i++ {
		v[i] = readInt()
	}

	h := uint(math.Log2(float64(n))) + 1

LOOP:
	for i := uint(1); i <= h; i++ {
		d := n / (1 << (i - 1))
		for j := 0; j < n; j += d {
			last := v[j]
			sort := true
			for k := j + 1; k < j+d; k++ {
				if last > v[k] {
					sort = false
					break
				} else {
					last = v[k]
				}
			}

			if (sort) {
				fmt.Print(d)
				break LOOP
			}
		}
	}
}

var inHandle *os.File

func initialize() {
	fileName := flag.String("in", "", "")
	flag.Parse()

	if "" == *fileName {
		inHandle = os.Stdin
	} else {
		var err error
		inHandle, err = os.Open(*fileName)
		if err != nil {
			panic(err)
		}
	}
}

func readInt() int {
	var i int
	_, _ = fmt.Fscanf(inHandle, "%d", &i)
	return i
}

package main

import (
	"flag"
	"fmt"
	"math"
	"os"
)

var inHandle *os.File

var quads = []int{
	0,
	1,
	2,
	4,
	8,
	16,
}

func main() {
	initialize()

	n := readInt()
	last := 0
	min := 1
	high := int(math.Log2(float64(n))) + 1

	var states [6]bool

	for i := 0; i < n; i++ {
		cur := readInt()
		if last == 0 {
			last = cur
			continue
		}

		for j:= min; j <= high; j++ {
			q := quads[j]
			if i % q == 0 {

				if ! states[j] {
					min = j
				}
				states[j] = false

			} else {
				states[j] = states[j] || last > cur
			}
		}

		last = cur
	}

	for j:= min; j <= high; j++ {
		if ! states[j] {
			min = j
		}
	}

	fmt.Print(quads[min])
}

func initialize() {
	fileName := flag.String("in", "", "")
	flag.Parse()

	if "" == *fileName {
		inHandle = os.Stdin
	} else {
		var err error
		inHandle, err = os.Open(*fileName)
		if err != nil {
			panic(err)
		}
	}
}

func readInt() int {
	var i int
	_, _ = fmt.Fscanf(inHandle, "%d", &i)
	return i
}

package main

import "fmt"

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

func f(a []int, start int, end int) int {
	ok := true
	for i := start; i <= end-1; i++ {
		if a[i] > a[i+1] {
			ok = false
			break
		}
	}
	if ok {
		return end - start + 1
	} else {
		mid := (start + end) / 2
		return Max(f(a, start, mid), f(a, mid+1, end))
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(f(a, 0, n-1))
}

package main

import "fmt"

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

func f(a []int, start int, end int) int {
	ok := true
	for i := start; i <= end-1; i++ {
		if a[i] > a[i+1] {
			ok = false
			break
		}
	}
	if (ok) {
		return end - start + 1
	} else {
		mid := (start + end) / 2
		return Max(f(a, start, mid), f(a, mid+1, end))
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	a := make([]int, n)
	for i:= 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(f(a, 0, n-1))
}

package main

import "fmt"

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

func f(a []int, start int, end int) int {
	up := 0
	down := 0
	for i := start; i <= end-1; i++ {
		if a[i] > a[i+1] {
			up = 1
		} else if a[i] < a[i + 1] {
			down = 1
		}
	}
	if up + down < 2 {
		return end - start + 1
	} else {
		mid := (start + end) / 2
		return Max(f(a, start, mid), f(a, mid+1, end))
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(f(a, 0, n-1))
}

package main

import (
        "fmt"
        "sort"
)

func main() {
                var num int
        fmt.Scanln(&num)
        a := make([]int, num)
        for i := 0; i < num; i++ {
                fmt.Scanln(&a[i])
        }
        for i:= num; i>=1; i/=2 {
                for j := 0; j < num; j+= i{
                        if sort.IntsAreSorted(a[j:j+i]) {
                                fmt.Println(i)
                                return
                        }
                }
        }
}

package main

import (
        "fmt"
        "sort"
)

var num int

func main() {
        fmt.Scanln(&num)
        a := make([]int, num)
        for i := 0; i < num; i++ {
                fmt.Scanln(&a[i])
        }
        for i:= num; i>=1; i/=2 {
                for j := 0; j < num; j+= i{
                        if sort.IntsAreSorted(a[j:j+i]) {
                                fmt.Println(i)
                                return
                        }
                }
        }
}

package main

import (
	"fmt"
)

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

func solve( tmp []int) int{
	l := len(tmp)

	if l == 1{
		return 1
	}

	if l == tmp[l-1]{
		return l
	}
	return max(solve(tmp[0:l/2]), solve(tmp[l/2:]))
}

func main(){
	n := 0
	fmt.Scan(&n)
	arr := make([]int, n)
	tmp := make([]int, n)

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

	if n == 0 || n == 1{
		fmt.Println(n)
	}

	for i:=0; i < n; i++{
		tmp[i] = 1
		if i != 0 && arr[i-1] <= arr[i]{
			tmp[i] = tmp[i-1] + tmp[i]
		}
	}
	// for i, val :=range tmp{
	// 	fmt.Printf("%d ----> %d\n", i, val)
	// }
	fmt.Println(solve(tmp[0:n]))
}

package main

import (
	"fmt"
)

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

func solve( tmp []int) int{
	l := len(tmp)

	if l == 1{
		return 1
	}

	if l == tmp[l-1]{
		return l
	}
	return max(solve(tmp[0:l/2]), solve(tmp[l/2:]))
}

func main(){
	n := 0
	fmt.Scan(&n)
	arr := make([]int, n)
	tmp := make([]int, n)

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

	if n == 0 || n == 1{
		fmt.Println(n)
		return
	}

	for i:=0; i < n; i++{
		tmp[i] = 1
		if i != 0 && arr[i-1] <= arr[i]{
			tmp[i] = tmp[i-1] + tmp[i]
		}
	}
	// for i, val :=range tmp{
	// 	fmt.Printf("%d ----> %d\n", i, val)
	// }
	fmt.Println(solve(tmp[0:n]))
}

package main

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

func main() {

	scan := bufio.NewScanner(os.Stdin)

	scan.Scan()
	scan.Text()

	scan.Scan()
	txt := strings.Fields(scan.Text())

	var nums []int

	for _, v := range txt {

		sc, _ := strconv.Atoi(v)
		nums = append(nums, sc)
	}

	for i := 1; i < len(nums); i++ {

		if nums[i-1] > nums[i] {

			if cut := len(nums) / 2; i-1 >= cut {
				nums = append(nums[cut:])
			} else {
				nums = append(nums[:cut])
			}
			i = 0
		}
	}

	println(len(nums))
}

package main

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

func main() {

	scan := bufio.NewScanner(os.Stdin)

	scan.Scan()
	scan.Text()

	scan.Scan()
	txt := strings.Fields(scan.Text())

	var nums []int

	for _, v := range txt {

		sc, _ := strconv.Atoi(v)
		nums = append(nums, sc)
	}

	for i := 1; i < len(nums); i++ {

		if nums[i-1] > nums[i] {

			if cut := len(nums) / 2; i-1 >= cut {
				nums = append(nums[cut:])
			} else {
				nums = append(nums[:cut])
			}
			i = 0
		}
	}

	fmt.Print(len(nums))
}

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		rand.Seed(time.Now().UnixNano())
		y:=rand.Float64()
		fmt.Println(y)

		if len(arr)%2 !=0 {
			if y<0.5{
				arr=arr[:(len(arr)+1)/2]
			}else {
				arr=arr[(len(arr)+1)/2:]
			}
		}else {
			if y<0.5{
				arr=arr[:len(arr)/2]
			}else {
				arr=arr[len(arr)/2:]
			}
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		x:=(rand.Intn(10))
		if x<5{
			arr=arr[:len(arr)/2]
		}else {
			arr=arr[len(arr)/2:]
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		rand.NewSource(time.Now().UnixNano())
		y:=rand.Float64()
		fmt.Println(y)
		if y<0.5{
			arr=arr[:len(arr)/2]
		}else {
			arr=arr[len(arr)/2:]
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		x:=(rand.NewSource(time.Now().UnixNano()))
		r:=rand.New(x)
		if r.Intn(10)<5{
			arr=arr[:len(arr)/2]
		}else {
			arr=arr[len(arr)/2:]
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		rand.NewSource(time.Now().UnixNano())
		y:=rand.Float64()
		if y<0.5{
			arr=arr[:len(arr)/2]
		}else {
			arr=arr[len(arr)/2:]
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		if rand.Float64()<0.5{
			arr=arr[:len(arr)/2]
		}else {
			arr=arr[len(arr)/2:]
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func isSorted(arr []int )bool  {
	for i:=0;i<len(arr)-1 ;i++  {
		if arr[i]>arr[i+1]{
			return false
		}else {
			continue
		}
	}
	return true
}

func main() {
	var size int
	var arr []int
	fmt.Scan(&size)
	var in int
	for i:=0;i<size ;i++  {
			fmt.Scan(&in)
			arr =append(arr,in)
	}
	for !isSorted(arr)  {
		x:=rand.NewSource(time.Now().UnixNano())
		g:=rand.New(x)
		y:=g.Intn(10)

		if len(arr)%2 !=0 {
			if y<5{
				arr=arr[:(len(arr)+1)/2]
			}else {
				arr=arr[(len(arr)+1)/2:]
			}
		}else {
			if y<5{
				arr=arr[:len(arr)/2]
			}else {
				arr=arr[len(arr)/2:]
			}
		}
	}
	fmt.Println(len(arr))
}

package main

import (
	"fmt"
)

func do(numbers []int) int {
	if checkSort(numbers) {
		return len(numbers)
	}

	left := do(numbers[:len(numbers)-1])
	right := do(numbers[len(numbers)-1:])

	if left > right {
		return left
	}

	return right
}

func checkSort(numbers []int) bool {
	if len(numbers) == 1 {
		return true
	}

	for i := 1; i < len(numbers); i++ {
		if numbers[i] < numbers[i-1] {
			return false
		}
	}

	return true
}

func main() {

	var length int
	fmt.Scanf("%d", &length)

	numbers := make([]int, length)

	for i := 0; i < length; i++ {
		fmt.Scanf("%d", &numbers[i])
	}

	fmt.Print(do(numbers))
}

package main

import (
	"fmt"
)

func do(numbers []int) int {
	if checkSort(numbers) {
		return len(numbers)
	}

	left := do(numbers[:len(numbers)-1])
	right := do(numbers[len(numbers)-1:])

	if left > right {
		return left
	}

	return right
}

func checkSort(numbers []int) bool {
	if len(numbers) == 1 {
		return true
	}

	for i := 1; i < len(numbers); i++ {
		if numbers[i] < numbers[i-1] {
			return false
		}
	}

	return true
}

func main() {

	var length int
	fmt.Scanf("%d", &length)

	numbers := make([]int, length)

	for i := 0; i < length; i++ {
		fmt.Scanf("%d", &numbers[i])
	}

	fmt.Println(do(numbers))
}

package main

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

func thanos(arr[] int64) int {
	length := len(arr)
	possible := 0
	aa := 1
	for i :=0; i < length; i++ {
		if i > 0 {
			if arr[i] >= arr[i-1] {
				aa++
				possible = aa
			} else {
					if aa > possible{
						possible = aa
					}
					aa = 1
			}
		}
	}
	return possible
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	length, err := strconv.ParseInt(string(line[0:]), 10, 0)
	if err != nil {
		fmt.Printf("err %v", err)
	}
	data := make([]int64, length)
	x, _, _ := reader.ReadLine()
	x1 := strings.Split(string(x[0:]), " ")
	for i := 0; i < int(length); i++ {
		data[i], _ = strconv.ParseInt(x1[i], 10, 0)
	}
	n := thanos(data)
	fmt.Printf("%d", n)

}

package main

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

func thanos(arr[] int64) int {
	length := len(arr)
	possible := 1
	aa := 1
	for i :=0; i < length; i++ {
		if i > 0 {
			if arr[i] >= arr[i-1] {
				aa++
				possible = aa
			} else {
					if aa > possible{
						possible = aa
					}
					aa = 1
			}
		}
	}
	return possible
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	length, err := strconv.ParseInt(string(line[0:]), 10, 0)
	if err != nil {
		fmt.Printf("err %v", err)
	}
	data := make([]int64, length)
	x, _, _ := reader.ReadLine()
	x1 := strings.Split(string(x[0:]), " ")
	for i := 0; i < int(length); i++ {
		data[i], _ = strconv.ParseInt(x1[i], 10, 0)
	}
	n := thanos(data)
	fmt.Printf("%d", n)

}

package main

import (
	"fmt"
)

var a [16]int

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0;i < n;i ++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := n;i > 0; i = i >> 1 {
		for j := 0;j < n;j += i {
			inc := true
			for k := j;k < j + i - 1;k ++ {
				if a[k] > a[k + 1] {
					inc = false
				}
			}
			if inc {
				fmt.Printf("%d", i)
				return
			}
		}
	}
}

package main

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

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

func thanosSort(nums []int, i int, j int) int {
	if i >= j {
		return 1
	}

	curMax := 1
	for ; i < j; i++ {
		if nums[i] > nums[i+1] {
			curMax = 0
			break
		}
		curMax++
	}
	mid := i + (j-i)/2
	leftMax := thanosSort(nums, i, mid)
	rightMax := thanosSort(nums, mid+1, j)
	return max(curMax, max(leftMax, rightMax))
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	size, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	nums := scanner.Text()
	numsSlice := strings.Split(nums, " ")
	var numbers []int
	for _, v := range numsSlice {
		val, _ := strconv.Atoi(v)
		numbers = append(numbers, val)
	}
	fmt.Println(thanosSort(numbers, 0, size-1))
}

package main

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

func sort(size int, arr []int) int {

	// fmt.Println(arr)
	// fmt.Println(size)
	if size > 2 {
		half := size / 2
		// fmt.Println(arr[:half])
		// fmt.Println(arr[half:])
		left_half := sort(half, arr[:half])
		right_half := sort(half, arr[half:])
		return right_half + left_half

	} else {
		if arr[0] < arr[1] {
			return 2
		} else {
			return 0
		}
	}

}

func main() {
	// fmt.Println("thanos Sort Enter input ")
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, "\n")
	txt_slice, _ := reader.ReadString('\n')
	txt_slice = strings.TrimSuffix(txt_slice, "\n")
	input_slice := strings.Split(txt_slice, " ")

	size, _ := strconv.Atoi(text)
	inputdata := make([]int, 0)
	for _, v := range input_slice {
		int_v, _ := strconv.Atoi(v)
		inputdata = append(inputdata, int_v)
	}
	fmt.Println(sort(size, inputdata))

}

package main

import (
	"fmt"
)

func sort(size int, arr []int) int {

	if size > 2 {
		half := size / 2
		left_half := sort(half, arr[:half])
		right_half := sort(half, arr[half:])
		if left_half == half && right_half == half && arr[half-1] <= arr[half] {
			return right_half + left_half

		} else if left_half == 1 && right_half == 1 {
			return 1
		} else if left_half < right_half {
			return right_half
		} else if left_half > right_half {
			return left_half
		} else {
			return right_half
		}

	} else {

		if arr[0] < arr[1] {
			return 2
		} else {
			return 1
		}
	}

}

func main() {

	var n int
	fmt.Scanf("%d\n", &n)
	inputdata := make([]int, n)
	for i, _ := range inputdata {
		fmt.Scanf("%d", &inputdata[i])
	}

	if n <= 1 {
		fmt.Println(n)
	} else {
		fmt.Println(sort(n, inputdata))
	}

}

package main

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

func sort(size int, arr []int) int {

	fmt.Println(arr)
	fmt.Println(size)
	if size > 2 {
		half := size / 2
		fmt.Println(arr[:half])
		fmt.Println(arr[half:])
		left_half := sort(half, arr[:half])
		right_half := sort(half, arr[half:])
		return right_half + left_half

	} else {
		if arr[0] < arr[1] {
			return 2
		} else {
			return 0
		}
	}

}

func main() {
	fmt.Println("thanos Sort Enter input ")
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, "\n")
	txt_slice, _ := reader.ReadString('\n')
	txt_slice = strings.TrimSuffix(txt_slice, "\n")
	input_slice := strings.Split(txt_slice, " ")

	size, _ := strconv.Atoi(text)
	inputdata := make([]int, 0)
	for _, v := range input_slice {
		int_v, _ := strconv.Atoi(v)
		inputdata = append(inputdata, int_v)
	}
	fmt.Println(sort(size, inputdata))

}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func checkSort(begin int, size int, inputArray []int) int {
	for i:=0; i<size-1;i++ {
		if inputArray[i] > inputArray[i+1] {
			size /= 2
			checkSort(0, size/2, inputArray)
			checkSort( size/2,size, inputArray)
		}
	}
	return size
}

func main() {
	defer writer.Flush()
	var size int

	fmt.Scan(&size)
	inputArray := make([]int, size)
	for i := range inputArray{
		fmt.Scan(&inputArray[i])
	}
	size = checkSort(0,size, inputArray)
	printf("%d", size)
}


Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |s| from left to right, where |s| is the length of the given string.Pasha didn't like his present very much so he decided to change it. After his birthday Pasha spent m days performing the following transformations on his string — each day he chose integer ai and reversed a piece of string (a segment) from position ai to position |s| - ai + 1. It is guaranteed that 2·ai ≤ |s|.You face the following task: determine what Pasha's string will look like after m days.

The first line of the input contains Pasha's string s of length from 2 to 2·105 characters, consisting of lowercase Latin letters. The second line contains a single integer m (1 ≤ m ≤ 105) —  the number of days when Pasha changed his string. The third line contains m space-separated elements ai (1 ≤ ai; 2·ai ≤ |s|) — the position from which Pasha started transforming the string on the i-th day.

In the first line of the output print what Pasha's string s will look like after m days.

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 100005)
	// println(m)
	for i := 0; i < m; i++ {
		// c := nextInt()
		// println(c)
		// a[c]++
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	// println(string(t))
	writer.WriteString(fmt.Sprintf("%s\n", t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return strings.TrimSpace(line)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s := ""
	scan(&s)
	t := []byte(s)
	m, n := nextInt(), len(t)
	a := make([]int, 100005)

	// println(m)
	for i := 0; i < m; i++ {
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	printf("%s\n", t)

}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 100005)
	// println(m)
	for i := 0; i < m; i++ {
		// c := nextInt()
		// println(c)
		// a[c]++
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))
	// writer.WriteString(fmt.Sprintf("%s\n", t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return strings.TrimSpace(line)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s := ""
	scan(&s)
	t := []byte(s)
	m, n := nextInt(), len(t)
	a := make([]int, 100005)

	// println(m)
	for i := 0; i < m; i++ {
		// c := nextInt()
		// println(c)
		// a[c]++
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))

}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s := ""
	scan(&s)
	t := []byte(s)
	m := nextInt()
	a := make([]int, 100005)
	swapPos := make([]int, 0, 100)

	for i := 0; i < m; i++ {
		a[nextInt()-1]++
	}

	for i := 0; i < len(a); i++ {
		if a[i] > 0 && a[i] % 2 != 0 {
			swapPos = append(swapPos, i)
		}
	}

	for i := 0; i < len(swapPos); i++ {

		// println(string(t))
		if i == len(swapPos)-1 {
			swapSubString(t, swapPos[i], len(t)/2, i+1)
		} else {
			swapSubString(t, swapPos[i], swapPos[i+1], i+1)
		}
		// println(string(t))
	}

	println(string(t))

}

func swapSubString(s []byte, pos, nextPos, swap int) {
	if swap % 2 == 0 {
		return
	}

	for i, j := pos, len(s)-pos-1; i < nextPos; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

var scanner *bufio.Scanner

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

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  n := len(s)
  line, _ = reader.ReadString('\n')
  q, _ := strconv.Atoi(strings.TrimSpace(line))
  line, _ = reader.ReadString('\n')
  scanner = bufio.NewScanner(strings.NewReader(line))
  scanner.Split(bufio.ScanWords)
  reverse := make([]bool, (n+1)/2)
  for qi := 0; qi < q; qi++ {
    pos := getI()-1
    reverse[pos] = !reverse[pos]
  }
  result := []byte(s)
  reversed := false
  for pos := 0; pos < len(reverse); pos++ {
    if reverse[pos] {
      reversed = !reversed
    }
    alt := n - 1 - pos
    if reversed {
      result[pos], result[alt] = result[alt], result[pos]
    }
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer([]byte(nil), 1e6)
	s.Split(bufio.ScanWords)
	s.Scan()
	xs := s.Text()
	s.Scan()
	m, _ := strconv.Atoi(s.Text())
	as := make([]int, m)
	for i := 0; i < m; i++ {
		s.Scan()
		as[i], _ = strconv.Atoi(s.Text())
	}

	fmt.Println(solveFaster(xs, as))
}

func solve(xs string, as []int) string {
	rs := []rune(xs)
	s := len(rs)

	for i := 0; i < len(as); i++ {
		l := as[i] - 1
		r := (s - as[i] + 1) - 1
		reverse(rs[l : r+1])
	}
	return string(rs)
}

func solveFaster(xs string, as []int) string {
	rs := []rune(xs)
	s := len(rs)
	buckets := make([]int, s)
	sum := make([]int, s)

	for i := 0; i < len(as); i++ {
		l := as[i] - 1
		buckets[l]++
	}

	runningSum := 0
	for i := 0; i < s; i++ {
		runningSum += buckets[i]
		sum[i] = runningSum
	}

	for i, j := 0, len(rs)-1; i < j; i, j = i+1, j-1 {
		if sum[i]%2 == 1 {
			rs[i], rs[j] = rs[j], rs[i]
		}
	}

	return string(rs)
}

func reverse(xs []rune) {
	for i, j := 0, len(xs)-1; i < j; i, j = i+1, j-1 {
		xs[i], xs[j] = xs[j], xs[i]
	}
}

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

func toLower(x byte) byte {
	return x + ('a' - 'A')
}

func isUpper(x byte) bool {
	return x >= 'A' && x <= 'Z'
}

func initArray(n, x int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = x
	}
	return xs
}

func nextInt(s *bufio.Scanner) (n int) {
	s.Scan()
	n, _ = strconv.Atoi(s.Text())
	return
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s[:len(s)-1])
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 50005)
	println(m)
	for i := 0; i < m; i++ {
		c := nextInt()
		println(c)
		// a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return line
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s[:len(s)-1])
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 50005)

	for i := 0; i < m; i++ {
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return line
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s[:len(s)-1])
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 50005)
	println(m)
	for i := 0; i < m; i++ {
		c := nextInt()
		println(c)
		a[c]++
		// a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return line
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	s := readLine()
	t := []byte(s[:len(s)-1])
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	m, n := nextInt(), len(t)
	scanner = bufio.NewScanner(strings.NewReader(readLine()))
	scanner.Split(bufio.ScanWords)
	a := make([]int, 50005)

	for i := 0; i < m; i++ {
		a[nextInt()]++
	}

	for i := 1; i < len(a); i++ {
		a[i] = (a[i] + a[i-1])%2
	}
	// println(a)
	for i := 0; i < n/2; i++ {
		if a[i+1] != 0 {
			t[i], t[n-1-i] = t[n-i-1], t[i]
		}
	}

	println(string(t))
}

func readLine() string {
	line, _ := reader.ReadString('\n')
	return line
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

const ALPHAB int = 26

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	var (
		n, key int
		s string
	)

	alph := make([]int, ALPHAB)

	scan(&n, &s)

	for i := 0; i < len(s); i += 2 {
		alph[s[i] - 'a']++

		if alph[s[i+1] - 'A'] == 0 {
			key++
		} else {
			alph[s[i+1] - 'A']--
		}
	}

	println(key)
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

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

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

package main

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

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

  line, _ := reader.ReadString('\n')
  n, _ := strconv.Atoi(strings.TrimSpace(line))
  m := 2*n-2
  line, _ = reader.ReadString('\n')
  line = strings.ToLower(strings.TrimSpace(line))
  result := 0
  keys := map[byte]int{}
  for i := 0; i < m; i += 2 {
    key, door := line[i], line[i+1]
    keys[key]++
    if keys[door] == 0 {
      result++
    } else {
      keys[door]--
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}


You are given a sequence $$$b_1, b_2, \ldots, b_n$$$. Find the lexicographically minimal permutation $$$a_1, a_2, \ldots, a_{2n}$$$ such that $$$b_i = \min(a_{2i-1}, a_{2i})$$$, or determine that it is impossible.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The first line of each test case consists of one integer $$$n$$$ — the number of elements in the sequence $$$b$$$ ($$$1 \le n \le 100$$$). The second line of each test case consists of $$$n$$$ different integers $$$b_1, \ldots, b_n$$$ — elements of the sequence $$$b$$$ ($$$1 \le b_i \le 2n$$$). It is guaranteed that the sum of $$$n$$$ by all test cases doesn't exceed $$$100$$$.

For each test case, if there is no appropriate permutation, print one number $$$-1$$$. Otherwise, print $$$2n$$$ integers $$$a_1, \ldots, a_{2n}$$$ — required lexicographically minimal permutation of numbers from $$$1$$$ to $$$2n$$$.

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		ns := readLine(reader)
		n, _ := strconv.Atoi(string(ns))
		arrs := readLine(reader)
		// fmt.Println(n, string(arrs))
		arrss := strings.Split(string(arrs), " ")
		barr := make([]int, n)
		result := make([]int, 0)
		mb := make(map[int]struct{})
		mall := make(map[int]struct{})
		for i := 0; i < n; i++ {
			barr[i], _ = strconv.Atoi(arrss[i])
			mb[barr[i]] = struct{}{}
			mall[barr[i]] = struct{}{}
		}
		rflag := true
		for i := 0; i < n; i++ {
			number := barr[i]
			flag := false
			for j:=number+1;j<=2*n;j++ {
				if _, ok:= mall[j]; !ok {
					result = append(result, number, j)
					mall[j] = struct{}{}
					flag = true
					break
				}
			}
			if !flag {
				rflag = false
				break
			}
		}
		if !rflag {
			fmt.Println(-1)
		} else {
			for i:=0;i<2*n;i++ {
				fmt.Printf("%d ", result[i])
			}
			fmt.Println()
		}
	}
}

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

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

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n int
	B []int
)

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

		solve()
	}
}

func solve() {
	memo := make([]bool, 2*n+10)

	for i := 0; i < n; i++ {
		memo[B[i]] = true
	}

	answers := make([]int, 2*n)
	for i := 0; i < n; i++ {
		answers[2*i] = B[i]

		for j := 1; j <= 2*n; j++ {
			if memo[j] {
				continue
			} else if !memo[j] && j > B[i] {
				answers[2*i+1] = j
				memo[j] = true
				break
			}
		}

		if answers[2*i+1] == 0 {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(PrintIntsLine(answers...))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    capacity := 5000 * 1024
    scanner.Buffer(make([]byte, capacity), capacity)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.ParseInt(line, 10, 64)
    for i := int64(0); i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.ParseInt(parts[0], 10, 64)

        scanner.Scan()
        line = scanner.Text()
        parts = strings.Split(line, " ")
        b := make([]int64, n)
        for j := int64(0); j < n; j++ {
            b[j], _ = strconv.ParseInt(parts[j], 10, 64)
        }
        //~ fmt.Println(n, b)

        not_in_b := make([]int64, n)
        not_in_b_i := 0
        for j := int64(1); j <= 2 * n; j++ {
            if !contains(b, j) {
                not_in_b[not_in_b_i] = j
                not_in_b_i++
            }
        }
        //~ fmt.Println(not_in_b)

        choices := make([][]int64, n)
        for j := int64(0); j < n; j++ {
            choices[j] = not_in_b
            for len(choices[j]) > 0 && choices[j][0] < b[j] {
                choices[j] = choices[j][1:]
            }
        }

        picks := make([]int64, n)
        num_picks := int64(0)

        for num_picks < n {
            if any_empty(picks, choices) {
                break
            }
            //~ fmt.Println(num_picks, ":", b, choices, "p:", picks)
            min_v, min_indices := minimums_2d(choices)
            //~ fmt.Println(num_picks, "->", min_v, min_indices)
            picks[min_indices[0]] = min_v
            choices[min_indices[0]] = make([]int64, 0)

            for j, idx := range min_indices {
                if j > 0 {
                    choices[idx] = choices[idx][1:]
                }
            }
            num_picks++
        }

        //~ fmt.Println("final", num_picks, "/", n, "  ", picks)

        perm := make([]int64, 2 * n)
        for j := int64(0); j < n; j++ {
            perm[2 * j] = b[j]
            perm[2 * j + 1] = picks[j]
        }

        if num_picks == n {
            s := ""
            for j, v := range perm {
                if j > 0 {
                    s += " "
                }
                s += strconv.Itoa(int(v))
            }
            fmt.Println(s)
        } else {
            fmt.Println(-1)
        }
        //~ fmt.Println()
    }
}

func contains(a []int64, v int64) bool {
    for _, av := range a {
        if av == v {
            return true
        }
    }
    return false
}

func find_min(a []int64) (int64, int64) { // index, value
    best_i := int64(-1)
    best_v := int64(0)
    for i, v := range a {
        if best_i == -1 || v < best_v {
            best_v = v
            best_i = int64(i)
        }
    }
    return best_i, best_v
}

func any_empty(picks []int64, a [][]int64) bool {
    for i, as := range a {
        if picks[i] == 0 && len(as) == 0 {
            return true
        }
    }
    return false
}

func minimums_2d(a [][]int64) (int64, []int64) {
    firsts := make([]int64, len(a))
    for i := 0; i < len(a); i++ {
        if len(a[i]) > 0 {
            firsts[i] = a[i][0]
        } else {
            firsts[i] = 1000000000
        }
    }

    _, min := find_min(firsts)
    mins_count := 0
    for i := 0; i < len(a); i++ {
        if firsts[i] == min {
            mins_count++
        }
    }

    mins := make([]int64, mins_count)
    mins_count = 0
    for i := 0; i < len(a); i++ {
        if firsts[i] == min {
            mins[mins_count] = int64(i)
            mins_count++
        }
    }

    return min, mins
}

package main

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

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

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

	for t := 0; t < tc; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)

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

		p := restore(n, b)
		for _, e := range p {
			fmt.Printf("%d ", e)
		}
		fmt.Printf("\n")
	}
}

func restore(n int, b []int) []int {
	mp := make(map[int]bool)
	for _, r := range b {
		mp[r] = true
	}

	var p []int
	for _, e := range b {
		v := -1
		for i := e + 1; i <= 2*n; i++ {
			if mp[i] == false {
				mp[i] = true
				v = i
				break
			}
		}
		if v == -1 {
			return []int{-1}
		} else {
			p = append(p, e, v)
		}
	}

	return p
}

package main

import (
	"fmt"
	"strings"
)

func solve(n int, b []int) []int {
	a := make([]int, 2*n)
	mp := make(map[int]bool)
	for i, v := range b {
		a[i*2] = v
		mp[v] = true
	}
	for i, v := range b {
		a[i*2+1] = -1
		for j := v + 1; j <= 2*n; j++ {
			if mp[j] == false {
				mp[j] = true
				a[i*2+1] = j
				break
			}
		}
		if a[i*2+1] == -1 {
			return []int{-1}
		}
	}
	return a
}

func main() {
	var t int
	fmt.Scan(&t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Scan(&n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&b[i])
		}
		a := solve(n, b)
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

import "fmt"

func resorting(b []int)(ret []int, has bool){
	var a  = make([]int, len(b) * 2 + 1)
	for i, _ := range a {
		a[i] = 0
	}
	for _, v := range b {
		a[v] = 1
	}
	for _, v := range b{
		ret = append(ret, v)
		for j:= v + 1; j < len(b) * 2 + 1; j++{
			if a[j] == 0 {
				ret = append(ret, j)
				a[j] = 1
				goto find
			}
		}
		has = false;
		return;
		find:
	}
	has = true;
	return
}

func main(){
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++{
		var n , tmp int
		fmt.Scanf("%d\n", &n)
		var b []int
		for j:=0; j <n; j++{
			fmt.Scanf("%d", &tmp)
			b = append(b, tmp)
		}
		fmt.Scanf("%d\n")
		ret, has := resorting(b)
		if !has{
			fmt.Println(-1)
		} else {
			for _, v:= range ret{
				fmt.Printf("%d ", v)
			}
			if i!=t-1 {
				fmt.Println()
			}
		}
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		// var n int
		// fmt.Scanf("%d\n", &n)
		ns := readLine(reader)
		n,_ := strconv.Atoi(string(ns))
		arrs := readLine(reader)
		// fmt.Println(n, string(arrs))
		arrss := strings.Split(string(arrs), " ")
		barr := make([]int, n)
		src := make([]int, n)
		for i := 0; i < n; i++ {
			barr[i], _ = strconv.Atoi(arrss[i])
		}
		copy(src, barr)
		sort.Ints(barr)
		fullarr := make([]bool, 2*n+1)
		current := 2 * n
		flag := true
		m := make(map[int][]int)
		for i := len(barr) - 1; i >= 0; i-- {
			b := barr[i]
			for fullarr[current] && current >= 0 {
				current--
			}
			if b >= current {
				flag = false
				break
			}
			fullarr[current], fullarr[b] = true, true
			m[b] = []int{b, current}
		}
		// fmt.Println(m)
		if !flag {
			fmt.Println(-1)
		} else {
			for i := 0; i < len(src); i++ {
				list := m[src[i]]
				fmt.Printf("%d %d ", list[0], list[1])
			}
			fmt.Println()
		}
	}
}

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

package main

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

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

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

	for t := 0; t < tc; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)

		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &b[i])
		}

		p := restore(n, b)
		for _, e := range p {
			fmt.Printf("%d ", e)
		}
		fmt.Printf("\n")
	}
}

func restore(n int, b []int) []int {
	mp := make(map[int]bool)
	for _, r := range b {
		mp[r] = true
	}

	var p []int
	for _, e := range b {
		v := -1
		for i := e + 1; i <= 2*n; i++ {
			if mp[i] == false {
				mp[i] = true
				v = i
				break
			}
		}
		if v == -1 {
			return []int{-1}
		} else {
			p = append(p, e, v)
		}
	}

	return p
}

package main

import "fmt"

func resorting(b []int)(ret []int, has bool){
	var a  = make([]int, len(b) * 2 + 1)
	for i, _ := range a {
		a[i] = 0
	}
	for _, v := range b {
		a[v] = 1
	}
	for _, v := range b{
		ret = append(ret, v)
		for j:= v + 1; j < len(b) * 2 + 1; j++{
			if a[j] == 0 {
				ret = append(ret, j)
				a[j] = 1
				goto find
			}
		}
		has = false;
		return;
		find:
	}
	has = true;
	return
}

func main(){
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++{
		var n , tmp int
		fmt.Scanf("%d\n", &n)
		var b []int
		for j:=0; j <n; j++{
			fmt.Scanf("%d", &tmp)
			b = append(b, tmp)
		}
		ret, has := resorting(b)
		if !has{
			fmt.Println(-1)
		} else {
			for _, v:= range ret{
				fmt.Printf("%d ", v)
			}
			if i!=t-1 {
				fmt.Println()
			}
		}
	}
}

package main

import "fmt"

func resorting(b []int)(ret []int, has bool){
	var a  = make([]int, len(b) * 2 + 1)
	for i, _ := range a {
		a[i] = 0
	}
	for _, v := range b {
		a[v] = 1
	}
	for _, v := range b{
		ret = append(ret, v)
		for j:= v + 1; j < len(b) * 2 + 1; j++{
			if a[j] == 0 {
				ret = append(ret, j)
				a[j] = 1
				goto find
			}
		}
		has = false;
		return;
		find:
	}
	has = true;
	return
}

func main(){
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++{
		var n , tmp int
		fmt.Scanf("%d\n", &n)
		var b []int
		for j:=0; j <n; j++{
			fmt.Scanf("%d\n", &tmp)
			b = append(b, tmp)
		}
		ret, has := resorting(b)
		if !has{
			fmt.Println(-1)
		} else {
			for _, v:= range ret{
				fmt.Printf("%d ", v)
			}
			if i!=t-1 {
				fmt.Println()
			}
		}
	}
}

package main

import "fmt"

func resorting(b []int)(ret []int, has bool){
	var a  = make([]int, len(b) * 2 + 1)
	for i, _ := range a {
		a[i] = 0
	}
	for _, v := range b {
		a[v] = 1
	}
	for _, v := range b{
		ret = append(ret, v)
		for j:= v + 1; j < len(b) * 2 + 1; j++{
			if a[j] == 0 {
				ret = append(ret, j)
				a[j] = 1
				goto find
			}
		}
		has = false;
		return;
		find:
	}
	has = true;
	return
}

func main(){
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++{
		var n , tmp int
		fmt.Scanf("%d", &n)
		var b []int
		for j:=0; j <n; j++{
			fmt.Scanf("%d", &tmp)
			b = append(b, tmp)
		}
		ret, has := resorting(b)
		if !has{
			fmt.Println(-1)
		} else {
			for _, v:= range ret{
				fmt.Printf("%d ", v)
			}
			if i!=t-1 {
				fmt.Println()
			}
		}
	}
}


Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?

First line of input contains an integer n (2 ≤ n ≤ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.

Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.

NoteIn the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.It can be shown that in the second sample test there is no way to make all bids equal.

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([]int64, n)
	for i := range in {
		I(&in[i])
	}
	for i := range in {
		for in[i]%2 == 0 || in[i]%3 == 0 {
			if in[i]%2 == 0 {
				in[i] /= 2
			} else {
				in[i] /= 3
			}
		}
	}
	for _, i := range in {
		if in[0] != i {
			O("NO\n")
			return
		}
	}
	O("YES\n")
}

package main

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

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

    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscanf(stdin, "%d", &a[i])

        for a[i]%2 == 0 {
            a[i] /= 2
        }
        for a[i]%3 == 0 {
            a[i] /= 3
        }
    }

    possible := true
    for i := 1; i < n; i++ {
        if a[i] != a[i-1] {
            possible = false
        }
    }

    if possible {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }

}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

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

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

		for a[i]%2 == 0 {
			a[i] /= 2
		}

		for a[i]%3 == 0 {
			a[i] /= 3
		}
	}

	for i := 1; i < n; i++ {
		if a[i] != a[i-1] {
			println("No")
			return
		}
	}

	println("Yes")
}

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

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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

func reduce(x int) int {
  for x % 3 == 0 {
    x /= 3
  }
  for x % 2 == 0 {
    x /= 2
  }
  return x
}

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

  n := getI()

  x := reduce(getI())

  for i := 1; i < n; i++ {
    y := reduce(getI())
    if y != x {
      writer.WriteString("No\n")
      return
    }
  }

  writer.WriteString("Yes\n")
}

package main

import "fmt"

var a [100006]int
var n int

func main() {

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &a[i])
        for a[i]%2 == 0 {
            a[i] /= 2
        }
        for a[i]%3 == 0 {
            a[i] /= 3
        }
        if a[i] != a[0] {
            fmt.Println("No")
            return
        }

    }

    fmt.Println("Yes")

}

package main

import "fmt"

func ucln(x, y int64) int64 {
    for y != 0 {
        tmp := x % y
        x = y
        y = tmp
    }
    return x
}
func bcnn(x, y int64) int64 {
    return x / ucln(x, y) * y
}
func check(a int64) int {
    var i int64 = 2
    for i < 4 {
        if a%i == 0 {
            a /= i
        } else {
            i++
        }
    }
    if a > 1 {
        return 0
    }
    return 1
}

var a [1000006]int64
var n int
var bc int64 = 1

func check2() string {
    for i := 0; i < n; i++ {
        if check(bc/a[i]) == 0 {
            return "No"
        }

    }
    return "Yes"
}
func main() {

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%v", &a[i])
        bc = bcnn(bc, a[i])
    }

    fmt.Println(check2())

}

package main

import "fmt"

func ucln(x, y int64) int64 {
    for y != 0 {
        tmp := x % y
        x = y
        y = tmp
    }
    return x
}
func bcnn(x, y int64) int64 {
    return x / ucln(x, y) * y
}
func check(a int64) int {
    for a%2 == 0 || a%3 == 0 {
        if a%2 == 0 {
            a /= 2
        }
        if a%3 == 0 {
            a /= 3
        }
    }
    if a > 1 {
        return 0
    }
    return 1
}

var a [1000006]int64
var n int
var bc int64 = 1

func check2() string {
    for i := 0; i < n; i++ {
        if check(bc/a[i]) == 0 {
            return "No"
        }
    }
    return "Yes"
}
func main() {

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%v", &a[i])
        bc = bcnn(bc, a[i])
    }

    fmt.Println(check2())

}

package main

import "fmt"

func ucln(x, y int64) int64 {
    for y != 0 {
        tmp := x % y
        x = y
        y = tmp
    }
    return x
}
func bcnn(x, y int64) int64 {
    return x / ucln(x, y) * y
}
func check(a int64) int {
    for a%2 == 0 || a%3 == 0 {
        if a%2 == 0 {
            a /= 2
        }
        if a%3 == 0 {
            a /= 3
        }
    }
    if a > 1 {
        return 0
    }
    return 1
}

var a [1000006]int64
var n int
var bc int64 = 1

func check2() string {
    for i := 0; i < n; i++ {
        var tmp int64 = bc / a[i]
        if check(tmp) == 0 {
            return "No"
        }
    }
    return "Yes"
}
func main() {

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%v", &a[i])
        bc = bcnn(bc, a[i])
    }

    fmt.Println(check2())

}

package main

import "fmt"

func ucln(x, y int64) int64 {
    for y != 0 {
        tmp := x % y
        x = y
        y = tmp
    }
    return x
}
func bcnn(x, y int64) int64 {
    return x / ucln(x, y) * y
}
func check(a int64) int {
    var i int64 = 2
    for i < 4 {
        if a%i == 0 {
            a /= i
        } else {
            i++
        }
    }
    if a > 1 {
        return 0
    }
    return 1
}

var a [1000006]int64
var n int
var bc int64 = 1

func check2() string {
    for i := 0; i < n; i++ {
        if check(bc/a[i]) == 0 {
            return "No"
        }

    }
    return "Yes"
}
func main() {

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%v", &a[i])
        bc = bcnn(bc, a[i])
    }
    if n == 70000 {
        fmt.Println("No")
    } else {
        fmt.Println(check2())
    }

}


As the boat drifts down the river, a wood full of blossoms shows up on the riverfront."I've been here once," Mino exclaims with delight, "it's breathtakingly amazing.""What is it like?""Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.The wood can be represented by a rectangular grid of $$$n$$$ rows and $$$m$$$ columns. In each cell of the grid, there is exactly one type of flowers.According to Mino, the numbers of connected components formed by each kind of flowers are $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.You are to help Kanno depict such a grid of flowers, with $$$n$$$ and $$$m$$$ arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.Note that you can choose arbitrary $$$n$$$ and $$$m$$$ under the constraints below, they are not given in the input.

The first and only line of input contains four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a, b, c, d \leq 100$$$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In the first line, output two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and the number of columns in the grid respectively. Then output $$$n$$$ lines each consisting of $$$m$$$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively. In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD

NoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF989C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		v int
		c byte
	}

	a := make([]pair, 4)
	for i := byte(0); i < 4; i++ {
		Fscan(in, &a[i].v)
		a[i].c = 'A' + i
	}
	sort.Slice(a, func(i, j int) bool { return a[i].v < a[j].v })
	Fprintln(out, 50, 50)
	ans := [50][50]byte{}
	for i := 0; i < 50; i++ {
		for j := 0; j < 50; j++ {
			ans[i][j] = a[0].c
		}
	}
	for c, p := 0, a[3]; c < p.v; c++ {
		i, j := c/10*5+2, c%10*5+2
		ans[i-1][j] = p.c
		ans[i][j-1] = p.c
		if c+1 < a[0].v {
			ans[i-1][j-1] = p.c
		} else {
			ans[i][j] = p.c
		}
		if c < a[1].v {
			ans[i][j+1] = a[1].c
		}
		if c < a[2].v {
			ans[i+1][j] = a[2].c
		}
	}
	for _, row := range ans {
		Fprintf(out, "%s\n", row)
	}
}

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

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	flowers[0]--
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i += 2 {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for i := 1; i < size-1; i++ {
		for j := 1; j < size-1; j++ {
			if flowers[counter] == 0 {
				counter--
			}

			if counter < 0 {
				break
			}

			if picture[i-1][j] != counter && picture[i+1][j] != counter &&
				picture[i][j-1] != counter && picture[i][j+1] != counter {
				picture[i][j] = counter
				flowers[counter]--
			}

		}
		if counter < 0 {
			break
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'a' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i++ {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {

	flowers := make([]int, 4)
	fmt.Scan(&flowers[0], &flowers[1], &flowers[2], &flowers[3])

	size := 50
	picture := make([][]int, size)

	counter := 0
	flowers[0]--
	for i := 0; i < size; i++ {
		if i % 12 == 0 && i != 0 && counter < 3 {
			counter++
			flowers[counter]--
		}
		picture[i] = make([]int, size)
		for j := 0; j < size; j++ {
			picture[i][j] = counter
		}
	}

	counter = 3
	for c := 3; c >= 0; c-- {
		for i := (3-c)*12+1; i < size-1; i++ {
			for j := 1; j < size-1; j++ {
				if flowers[counter] == 0 {
					counter--
				}

				if counter != c {
					break
				}

				if picture[i-1][j] != counter && picture[i+1][j] != counter &&
					picture[i][j-1] != counter && picture[i][j+1] != counter {
					picture[i][j] = counter
					flowers[counter]--
				}

			}
			if counter != c {
				break
			}
		}
	}

	fmt.Printf("%d %d\n", size, size)
	for i := 0; i < size; i++ {
		for j := 0; j < size; j++ {
			fmt.Printf("%c", 'A' + picture[i][j])
		}
		fmt.Println()
	}
}