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.


-----Input-----

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.


-----Output-----

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.


-----Examples-----
Input
4
1 2 2 4

Output
4

Input
8
11 12 1 2 13 14 3 4

Output
2

Input
4
7 6 5 4

Output
1



-----Note-----

In 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.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = [int(ai) for ai in input().split()]

def solve(x):
    n = len(x)
    if sorted(x) == x:
        return n
    return max(solve(x[:n//2]), solve(x[n//2:]))

print(solve(a))


def helper(arr):
    if arr == sorted(arr): return len(arr)
    return max(helper(arr[:len(arr) // 2]), helper(arr[len(arr) // 2:]))

def main():
    n = int(input())
    arr = list(map(int, input().split()))
    print(helper(arr))
    return 0

main()

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

def rec(a):
    if all(a[i] <= a[i + 1] for i in range(len(a) - 1)):
        return len(a)
    x = len(a) // 2
    return max(rec(a[:x]), rec(a[x:]))

ii()
print(rec(li()))

n = m = int(input())
A = [int(x) for x in input().split()]

while True:
    if any(sorted(A[i:i+m]) == A[i:i+m] for i in range(0,n,m)):
        print(m)
        break
    m //= 2


def mp():
    return map(int, input().split())

def f(a):
    if sorted(a) == a:
        return len(a)
    return max(f(a[:len(a) // 2]), f(a[len(a) // 2:]))

n = int(input())
a = list(mp())
print(f(a))

n=int(input())
arr=list(map(int,input().split()))
ans=1
size=2
while(size<=n):
    i=0
    while(i<n):
        j=i
        flag=0
        while(j<i+size-1):
            if(arr[j]<=arr[j+1]):
                j+=1
            else:
                flag=1
                break
        if(flag==0):
            ans=max(ans,size)
        i+=size
    size=size*2
print(ans)




# -*- coding: utf-8 -*-


def rli():
    return list(map(int, input().split()))


def solve(nums):
    if nums == sorted(nums):
        return len(nums)
    return max(solve(nums[:len(nums) // 2]), solve(nums[len(nums) // 2:]))


def main():
    input()
    nums = rli()
    print(solve(nums))


def __starting_point():
    main()

__starting_point()

N = int(input())
A = [int(a) for a in input().split()]

def calc(X):
    if X == sorted(X):
        return len(X)
    A = X[:len(X)//2]
    B = X[len(X)//2:]
    return max(calc(A), calc(B))

print(calc(A))


def cek(arr):
    if arr == sorted(arr):
        return len(arr)
    else:
        return max(cek(arr[:len(arr) // 2]), cek(arr[len(arr) // 2:]))


n = int(input())

seq = list(map(int, input().split()))
print(cek(seq))


n = int(input())
a = [int(x) for x in input().strip().split()]

ans, k = 1, 2
while k <= n:
    i = 0
    while i < n:
        flag = True
        for j in range(k - 1):
            if a[i + j] > a[i + j + 1]:
                flag = False
                break
        if flag:
            ans = k
        i += k
    k = k * 2

print(ans)

def is_sorted(a, l, r):
    for i in range(l + 1, r):
        if a[i] < a[i - 1]:
            return False
    return True


def solve(a, l, r):
    if is_sorted(a, l, r):
        return r - l
    return max(solve(a, l, (r + l) // 2), solve(a, (r + l)//2, r))


def main() -> None:
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(a, 0, n))


def __starting_point():
    main()

__starting_point()

n = int(input())
l = list(map(int, input().split()))

def isSorted(a):
    for i in range(1, len(a)):
        if a[i] < a[i-1]:
            return False
    return True

def sort(a):
    if isSorted(a):
        return a
    t = len(a) // 2
    a1 = a[:t]
    a2 = a[t:]
    a1 = sort(a1)
    a2 = sort(a2)
    if (len(a1) >= len(a2)):
        return a1
    else:
        return a2

print(len(sort(l)))


N = int(input())
A = list(map(int, input().split()))

def longest(A):
    if A == sorted(A):
        return len(A)
    
    return max(longest(A[:len(A) // 2]), longest(A[len(A) // 2:]))

print(longest(A))

n = int(input())
arr = list(map(int,input().split()))
def func(temp_arr):
    if temp_arr == sorted(temp_arr):
        return len(temp_arr)
    return max(func(temp_arr[:len(temp_arr)//2]), func(temp_arr[len(temp_arr)//2:]))

print(func(arr))


def check(ar: list):
    ok = True
    for i in range(1, len(ar)):
        if ar[i] < ar[i - 1]:
            ok = False
            break
    if ok:
        return len(ar)
    else:
        return max(check(ar[:len(ar) // 2]), check(ar[len(ar) // 2:]))


n = int(input())
a = list(map(int, input().split()))
print(check(a))


def f(a):
	if a == sorted(a):
		return len(a)
	else:
		k = len(a) // 2
		if len(a) % 2 == 0:
			return max(f(a[:k]), f(a[k:]))
		else:
			return max(f(a[:k]), f(a[k:]), f(a[k+1:]), f(a[k+1:]))
	

n, a = int(input()), list(map(int, input().split()))
print(f(a))



def is_sorted(lst):
    it = lst[0]
    for i in range(1, len(lst)):
        if lst[i] < it:
            return False
        it = lst[i]
    return True


def do(lst):
    if is_sorted(lst):
        return len(lst)

    v1 = do(lst[:len(lst) // 2])
    v2 = do(lst[len(lst) // 2:])

    return max(v1, v2)


N = int(input())

A = list(map(int, input().split()))
print(do(A))

def f(A):
    if len(A) == 1:
        return 1
    else:
        if A == sorted(A):
            return len(A)
        else:
            return max(f(A[:len(A) // 2]), f(A[len(A) // 2:]))

n = int(input())
A = list(map(int, input().split()))
print(f(A))

n = int(input())
a = list(map(int, input().split()))
def check(x):
	if x != sorted(x):
		return max(check(x[:len(x) // 2]), check(x[len(x) // 2:]))
	return len(x)
print(check(a))

kk=lambda:map(int,input().split())
ll=lambda:list(kk())
def dp(ls):
	if sorted(ls) == ls: return len(ls)
	return max(dp(ls[:len(ls)//2]), dp(ls[len(ls)//2:]))
_ = input(), print(dp(ll()))


def is_sorted(a):
    prev = None

    for i in a:
        if prev is not None and i < prev:
            return False
        prev = i

    return True

def solve(a):
    if len(a) == 1:
        return 1

    if is_sorted(a):
        return len(a)

    return max(solve(a[:len(a)//2]), solve(a[len(a)//2:]))

def __starting_point():
    n = int(input())
    #n, m = (int(p) for p in input().split())
    a = [int(p) for p in input().split()]
    print(solve(a))

__starting_point()

n = int(input())
arr = [int(x) for x in input().split()]
if n == 1:
    print(1)
else:
    for i in 16, 8, 4, 2:
        if i > n:
            continue
        for k in range(0, n, i):
            if sorted(arr[k:k+i]) == arr[k:k+i]:
                print(i)
                return
    print(1)
    return

#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue
sys.setrecursionlimit(1000000)
#sys.stdin = open("input.txt", "r")

ans = []

def solve(x):
    if sorted(x) == x:
        ans.append(len(x))
    else:
        solve(x[:len(x)//2])
        solve(x[len(x)//2:])

n = int(input())
a = list(map(int, input().split()))

solve(a)
print(max(ans))

n=int(input())
a=[int(k) for k in input().split(" ")]

nn=n

res=1
while nn>1:
    jj=0
    while jj<n:
        if sorted(a[jj:jj+nn])==a[jj:jj+nn]:
            res=nn
            break
        jj+=nn
    if res>=nn:
        break
    nn>>=1
    
print(res)


n = int(input())
a = list(map(int, input().split()))


def sort_(a):
	mid = len(a) // 2
	if sorted(a) == a:
		return len(a)
	else:
		return max(sort_(a[:mid]), sort_(a[mid:]))

print(sort_(a))