CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from bisect import bisect_left
import sys


N = int(eval(input()))
Pn = [[i,j] for i,j in enumerate(list(map(int, sys.stdin.readline().rstrip().split())))]
Pn = sorted(Pn,key=lambda x:-x[1])

In = [Pn[0][0]]
ans = 0
for i,p in Pn[1:]:
  cnt = 0
  c = bisect_left(In,i)
  In.insert(c,i)

  # Choose leftside bigger
  if c > 0:
    l,r = 0,0
    if c == 1:
      l = In[c-1]+1
    elif c > 1:
      l = In[c-1]-In[c-2]
    if c == len(In)-1:
      r = N-In[c]
    elif c < len(In)-1:
      r = In[c+1]-In[c]
    cnt += l*r

  # Choose rightside bigger
  if c < len(In)-1:
    l,r = 0,0
    if c == len(In)-2:
      r = N-In[c+1]
    elif c < len(In)-2:
      r = In[c+2]-In[c+1]
    if c == 0:
      l = In[c]+1
    elif c > 0:
      l = In[c]-In[c-1]
    cnt += l*r
  ans += cnt*p

print(ans)

# Optimized solution
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N = int(eval(input()))
Pn = list(map(int, input().split()))

In = [0] * (N+1)
for i in range(N):
  In[Pn[i]] = i+1

cnt = 0
l = [0] + [i for i in range(N+1)]
r = [i+1 for i in range((N+1))] + [N+1]

for v in range(1, N+1):
  i = In[v]
  
  l1 = l[i]
  l2 = l[l1]
  r1 = r[i]
  r2 = r[r1]
  cnt += ((l1-l2) * (r1-i) + (i-l1) * (r2-r1)) * v
  
  l[r1] = l1
  r[l1] = r1
    
print(cnt)
# Original solution
def resolve():
    n = int(eval(input()))
    p = list(map(int, input().split()))
    second = sorted(p)[-2]
    dp = [[[0, 0] for _ in range(n)] for __ in range(n)]
    ans = 0
    for i in range(n - 1):
        dp[i][i + 1][1], dp[i][i + 1][0] = sorted([p[i], p[i + 1]])
        ans += dp[i][i + 1][1]
        for j in range(i + 2, n):
            _, dp[i][j][1], dp[i][j][0] = sorted(
                [dp[i][j - 1][0], dp[i][j - 1][1], p[j]])
            ans += dp[i][j][1]
            if dp[i][j][1] == second:
                ans += dp[i][j][1] * (n - j - 1)
                break
    print(ans)


if __name__ == '__main__':
    resolve()


# Optimized solution
def resolve():
    n = int(eval(input()))
    p = list(map(int, input().split()))
    second = sorted(p)[-2]
    # dp = [[[0, 0] for _ in range(n)] for __ in range(n)]
    ans = 0
    for i in range(n - 1):
        b, a = sorted([p[i], p[i + 1]])
        ans += b
        for j in range(i + 2, n):
            x = p[j]
            if x > a:
                a, b = x, a
            elif x > b:
                a, b = a, x
            else:
                a, b = a, b
            ans += b
            if b == second:
                ans += b * (n - j - 1)
                break
    print(ans)


if __name__ == '__main__':
    resolve()
# Original solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
P_list = list(map(int, input().split()))

# rev_P_list = []
# for P in (reversed(P_list)):
#     rev_P_list.append(P)

x_list_list = [[0 for i in range(N)] for i in range(N)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if j == i + 1:
            x_list_list[i][j] = sorted([P_list[i], P_list[j]], reverse=True)
            ans += x_list_list[i][j][1]
        else:
            tmp_list = [t for t in x_list_list[i][j - 1]]
            tmp_list.append(P_list[j])
            tmp_list = sorted(tmp_list, reverse=True)
            x_list_list[i][j] = [tmp_list[0], tmp_list[1]]
            ans += x_list_list[i][j][1]

print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
N = int(eval(input()))
P_list = list(map(int, input().split()))

# rev_P_list = []
# for P in (reversed(P_list)):
#     rev_P_list.append(P)

x_dic = {}
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if j == i + 1:
            x_dic["{}_{}".format(i, j)] = sorted([P_list[i], P_list[j]], reverse=True)
            ans += x_dic["{}_{}".format(i, j)][1]
        else:
            tmp_list = [t for t in x_dic["{}_{}".format(i, j - 1)]]
            tmp_list.append(P_list[j])
            tmp_list = sorted(tmp_list, reverse=True)
            x_dic["{}_{}".format(i, j)] = [tmp_list[0], tmp_list[1]]
            ans += x_dic["{}_{}".format(i, j)][1]

print(ans)
# Original solution
n = int(eval(input()))
ListP =[int(i) for i in input().split()]
#n = 10000
#ListP = [i for i in range(n)]
points = 0
ListPos2 = [0] * (n + 1)
for i, a in enumerate(ListP):
	ListPos2[a] = i + 1
ListPos = [0, 0] + [ListPos2[n]] + [n+1, n+1]
#ListTPos = [0] * (n+2) + [n+1, n+1]
ListTPos = [0] * (n + 1) + [n+1]
ListTPos[ListPos2[n]] = ListPos2[n]
pos = 0
for i in reversed(list(range(1,n))):
	posi = ListPos2[i]
	ListTPos[posi] =  posi
	for j in ListTPos[posi+1:]:
		if (j > 0):
			pos = ListPos.index(j)
			ListPos.insert(pos, posi)
			#pos = ListTPos[j]
			break
	l1 = ListPos[pos-1]
	l2 = ListPos[pos-2]
	h1 = ListPos[pos+1]
	h2 = ListPos[pos+2]
	points += i * ((posi-l1)*(h2-h1) + (h1-posi)*(l1-l2))
	#low1 = ListPos[pos] - ListPos[pos-1]
	#low2 = ListPos[pos-1] - ListPos[pos-2]
	#high1 = ListPos[pos+1] - ListPos[pos]
	#high2 = ListPos[pos+2] - ListPos[pos+1]
	#points += i * (low1 * high2 + high1 * low2)
	#print(i, ListPos)
	#print(points, low1, high2, high1, low2)
print(points)

# Optimized solution
n = int(eval(input()))
p = [int(i) for i in input().split()]

pos_list = [0] * n
for ind, i in enumerate(p):
	pos_list[i-1] = ind

left_nextInd = list(range(-1, n-1)) + [-1, -1]
right_nextInd = list(range(1, n+1)) + [n, n]

answer = 0
for i in range(1, n):
	ind = pos_list[i-1]
	l1 = left_nextInd[ind]
	l2 = left_nextInd[l1]
	r1 = right_nextInd[ind]
	r2 = right_nextInd[r1]

	answer += i * ((ind-l1) * (r2-r1) + (r1-ind) * (l1-l2))

	left_nextInd[r1] = l1
	right_nextInd[l1] = r1
print(answer)
# Original solution
import bisect

n = int(eval(input()))
p = list(map(int, input().split()))
pi = sorted(zip(p, list(range(n))))

index = [-1, -1, pi[n - 1][1], n, n]
ret = 0
for pos in range(n - 2, -1, -1):
    p, i = pi[pos]
    ii = bisect.bisect_left(index, i)
    ret += p * (index[ii - 1] - index[ii - 2]) * (index[ii] - i)
    ret += p * (i - index[ii - 1]) * (index[ii + 1] - index[ii])
    bisect.insort_left(index, i)
print(ret)

# Optimized solution
n = int(eval(input()))
p = list(map(int, input().split()))
pi = sorted(zip(p, list(range(n))))
left  = {i: i - 1 for i in range(n)}
right = {i: i + 1 for i in range(n)}
left[-1] = -1
right[n] = n

ret = 0
for p, i in pi:
    ret += p * (left[i] - left[left[i]]) * (right[i] - i)
    ret += p * (i - left[i]) * (right[right[i]] - right[i])
    l, r = left[i], right[i]
    right[l] = r
    left[r] = l
print(ret)
# Original solution
def main():
    import sys
    input=sys.stdin.readline
    from bisect import bisect,insort
    n=int(eval(input()))
    p=list(map(int,input().split()))
    p=[0]+p
    q=[0]*(n+1)
    for i in range(1,n+1):
        q[p[i]]=i
    lst=[0,q[n],n+1]
    ans=0
    for i in range(1,n):
        k=i
        i=n-i
        num=q[i]
        a=bisect(lst,num)
        if a==1:
            ans+=i*num*(lst[2]-lst[1])
            insort(lst,num)
        elif a==1+k:
            ans+=i*(n+1-num)*(lst[k]-lst[k-1])
            insort(lst,num)
        else:
            b=lst[a-2]
            c=lst[a-1]
            d=lst[a]
            e=lst[a+1]
            ans+=i*(d-num)*(c-b)+i*(num-c)*(e-d)
            insort(lst,num)
    print(ans)
if __name__=="__main__":
    main()

# Optimized solution
n=int(eval(input()))
p=list(map(int,input().split()))
f=[0]*(n+1)
for i in range(n):
    f[p[i]]=i+1
l=[0]+[i for i in range(n+1)]
r=[i+1 for i in range(n+1)]+[n+1]
ans=0
for i in range(1,n+1):
    x=f[i]
    l1,r1=l[x],r[x]
    l2,r2=l[l1],r[r1]
    ans+=i*((l1-l2)*(r1-x)+(x-l1)*(r2-r1))
    l[r1],r[l1]=l1,r1
print(ans)
# Original solution
import bisect

N = int(eval(input()))
P = list(map(int, input().split()))

place = [-1] * (N + 1)
for i in range(N):
    p = P[i]
    place[p] = i

ans = 0
big_place = [place[N]]
for i in range(N - 1, 0, -1):
    pos = bisect.bisect_left(big_place, place[i])
    if pos < len(big_place):
        right = big_place[pos]
    else:
        right = N
    if pos + 1 < len(big_place):
        right2 = big_place[pos + 1]
    else:
        right2 = N
    if pos - 1 >= 0:
        left = big_place[pos - 1]
    else:
        left = -1
    if pos - 2 >= 0:
        left2 = big_place[pos - 2]
    else:
        left2 = -1

    if left >= 0:
        left_cand = left - left2
    else:
        left_cand = 0
    right_cand = right - place[i]

    ans += i * left_cand * right_cand

    if right < N:
        right_cand = right2 - right
    else:
        right_cand = 0
    left_cand = place[i] - left
    ans += i * left_cand * right_cand

    big_place1 = big_place[:pos]
    big_place2 = big_place[pos:]
    big_place = big_place1 + [place[i]] + big_place2

print(ans)


# Optimized solution
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のRを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L


N = int(eval(input()))
P = list(map(int, input().split()))

place = [-1] * (N + 1)
for i in range(N):
    p = P[i]
    place[p] = i

ans = 0
big_place = Bit(N)
big_place.add(place[N] + 1, 1)
for i in range(N - 1, 0, -1):
    pos = place[i] + 1
    right = big_place.bisect_plus(pos, 1)
    right2 = big_place.bisect_plus(pos, 2)
    left = big_place.bisect_minus(pos, 1)
    left2 = big_place.bisect_minus(pos, 2)
    if left > 0:
        left_cand = left - left2
    else:
        left_cand = 0
    right_cand = right - pos
    ans += i * left_cand * right_cand

    if right < N + 1:
        right_cand = right2 - right
    else:
        right_cand = 0
    left_cand = pos - left
    ans += i * left_cand * right_cand

    big_place.add(pos, 1)

print(ans)
# Original solution
class SegmentTree:
    def __init__(self, a):
        self.padding = 0
        self.n = len(a)
        self.N = 2 ** (self.n-1).bit_length()
        self.data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        for i in range(2*self.N-2, 0, -2):
            self.data[(i-1)//2] = sum([self.data[i], self.data[i-1]])
    
    def __len__(self):
        return self.n
    
    def update(self, i, x):
        idx = self.N - 1 + i
        self.data[idx] = x
        while idx:
            idx = (idx-1) // 2
            self.data[idx] = sum([self.data[2*idx+1], self.data[2*idx+2]])
    
    def query(self, i, j):
        # [i, j)
        if i == j:
            return self.data[self.N - 1 + i]
        else:
            idx1 = self.N - 1 + i
            idx2 = self.N - 2 + j # 閉区間にする
            result = self.padding
            while idx1 + 1 < idx2:
                if idx1&1 == 0: # idx1が偶数
                    result = sum([result, self.data[idx1]])
                if idx2&1 == 1: # idx2が奇数
                    result = sum([result, self.data[idx2]])
                    idx2 -= 1
                
                idx1 //= 2
                idx2 = (idx2 - 1)//2
            
            if idx1 == idx2:
                result = sum([result, self.data[idx1]])
            else: # idx1 + 1 == idx2
                result = sum([result, self.data[idx1], self.data[idx2]])
            
            return result

def find_next(st, idx):
    n = len(st)
    idx_v = st.query(idx, idx)
    right_sum = st.query(idx, n) - idx_v
    if right_sum:
        left = idx
        right = n
        while left + 1 < right:
            mid = (left + right) // 2
            right_sum = st.query(idx, mid) - idx_v
            if right_sum >= 1:
                right = mid
            else:
                left = mid
        return left
    else:
        return n

def find_before(st, idx):
    if idx == 0:
        return -1
    left_sum = st.query(0, idx)
    if left_sum:
        left = 0
        right = idx
        while left + 1 < right:
            mid = (left + right) // 2
            left_sum = st.query(mid, idx)
            if left_sum:
                left = mid
            else:
                right = mid
        return left
    else:
        return -1


N = int(eval(input()))
P = list(enumerate(list(map(int, input().split()))))
P = sorted(P, key=lambda x:x[1], reverse=True)

a = [0]*N
st = SegmentTree(a)
ans = 0
for i, p in P:
  ir1 = find_next(st, i)
  ir2 = N if ir1==N else find_next(st, ir1)
  il1 = find_before(st, i)
  il2 = -1 if il1==-1 else find_before(st, il1)
  ans += ((ir1-i)*(il1-il2) + (ir2-ir1)*(i-il1)) * p
  st.update(i, 1)


print(ans)

# Optimized solution
N = int(eval(input()))
P = list(enumerate(list(map(int, input().split()))))
P = sorted(P, key=lambda x:x[1])

before_idx = list(range(-1, N-1)) + [-1, -1]
next_idx = list(range(1, N+1)) + [N, N]
ans = 0
for i, p in P:
  il1 = before_idx[i]
  il2 = before_idx[il1]
  ir1 = next_idx[i]
  ir2 = next_idx[ir1]
  ans += p * ((i-il1)*(ir2-ir1) + (ir1-i)*(il1 -il2))
  before_idx[ir1] = il1
  next_idx[il1] = ir1


print (ans)
# Original solution
N = int(eval(input()))
P = [int(x) - 1 for x in input().split()]

idx = [0] * N
for i in range(N):
    idx[P[i]] = i

ans = 0
for i in range(N - 2, -1, -1):
    find = False
    l1 = idx[i] + 1
    l2 = 0
    for j in range(idx[i] - 1, -1, -1):
        if i < P[j]:
            if not find:
                l1 = idx[i] - j
                l2 = j + 1
                find = True
            else:
                l2 = idx[i] - l1 - j
                break
    
    find = False
    r1 = N - idx[i]
    r2 = 0
    for j in range(idx[i] + 1, N):
        if i < P[j]:
            if not find:
                r1 = j - idx[i]
                r2 = N - j
                find = True
            else:
                r2 = j - r1 - idx[i]
                break
    ans += (i + 1) * (l1 * r2 + l2 * r1)

print(ans)

# Optimized solution
N = int(eval(input()))
P = [int(x) for x in input().split()]

PIdx = sorted([(i + 1, v) for i, v in enumerate(P)], key = lambda x: x[1])

L = [0]
for i in range(N + 1):
    L.append(i)

R = [i + 1 for i in range(N + 1)]
R.append(N + 1)

ans = 0
for i, v in PIdx:
    l1 = L[i]
    l2 = L[l1]
    r1 = R[i]
    r2 = R[r1]

    ans += v * ((i - l1) * (r2 - r1) + (l1 - l2) * (r1 - i))

    L[r1] = l1
    R[l1] = r1

print(ans)
# Original solution
#!/usr/bin/env python3
import sys
# from collections import Counter
INF = float("inf")


class MaxBit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s = max(s, self.tree[i])
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(self.tree[i], x)
            i += i & -i


class MinBit:
    def __init__(self, n):
        self.size = n
        self.tree = [n-1] * (n + 1)

    def sum(self, i):
        s = self.size-1
        while i > 0:
            s = min(s, self.tree[i])
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(self.tree[i], x)
            i += i & -i


def solve(N: int, P: "List[int]"):

    prev = MaxBit(N+2)
    foll = MinBit(N+2)
    seq = [0]*(N+2)

    inv = {p: i for i, p in enumerate(P)}
    # print(inv)
    # c = Counter()

    ans = 0
    for i in range(N, 0, -1):
        prev.add(inv[i]+2, inv[i]+1)
        foll.add(N-inv[i]+1, inv[i]+1)
        seq[inv[i]+1] = i

        # print("")
        # print("{}番目に{}を追加".format(inv[i]+1, i))
        # print("seq : ", seq)
        # print("prev: ", [prev.sum(j) for j in range(N+2)])
        # print("foll: ", [foll.sum(j) for j in range(N+2)][::-1])
        p = prev.sum(inv[i]+1)
        pp = prev.sum(p)
        f = foll.sum(N-inv[i])
        ff = foll.sum(N-f+1)
        # 前の数字との組み合わせ
        if p > 0:
            # (前、今) 前に伸ばす * 後ろに伸ばす
            ans += i*(p-pp)*(f-(inv[i]+1))
            # print("+ (A): ", i*(p-pp)*(f-(inv[i]+1)))
            # c[i] += (p - pp) * (f - (inv[i]+1))
        # 後ろの数字との組み合わせ
        if f < N+1:
            # (今、後) 前に伸ばす * 後に伸ばす
            ans += i*(inv[i]+1 - p) * (ff - f)
            # print("+ (B): ", i*(inv[i]+1 - p)*(ff-f))
            # c[i] += (ff - f) * ((inv[i]+1) - p)
    print(ans)
    # print([(i+1, c[i+1]) for i in range(N)])

    # guchoku = Counter()
    # for i in range(N):
    #     for j in range(i+1, N):
    #         guchoku[sorted(P[i:j+1])[-2]] += 1
    #         print(sorted(P[i:j+1])[-2], P[i:j+1])
    # print([(i+1, guchoku[i+1]) for i in range(N)])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)


if __name__ == '__main__':
    main()


# Optimized solution
N = int(eval(input()))
P = list(map(int, input().split()))

pos = {}
for i, p in enumerate(P):
    pos[p] = i+1

foll = [i+1 for i in range(N+1)]+[N+1]
prev = [0]+[i for i in range(N+1)]

ans = 0
for i in range(1, N+1):
    curr = pos[i]
    r = foll[curr]
    rr = foll[r]
    l = prev[curr]
    ll = prev[l]
    ans += (l-ll)*(r-curr)*i
    ans += (rr-r)*(curr-l)*i

    foll[l] = foll[curr]
    prev[r] = prev[curr]
    # print(*foll)
    # print(*prev)
print(ans)
# Original solution
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.depth = pow(2, n.bit_length())

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)

    # Return the minimum i that satisfies a_0 + a_1 + ... + a_i >= x
    def lower_bound(self, x):
        if x <= 0:
            return 0
        i = 0
        k = pow(2, self.depth)
        while k:
            if i + k < self.n and self.data[i + k] < x:
                x -= self.data[i + k]
                i += k
            k >>= 1
        return i


def main():
    N, *P = list(map(int, read().split()))

    index = [0] * (N + 1)
    for i, p in enumerate(P):
        index[p] = i

    bit = BIT(N)

    ans = 0
    for n in range(N, 0, -1):
        i = index[n]
        bit.add(i)
        x = bit.get_sum(i)

        left1 = left2 = -1
        right1 = right2 = N
        if x - 2 > 0:
            left2 = bit.lower_bound(x - 2)
        if x - 1 > 0:
            left1 = bit.lower_bound(x - 1)
        if x + 1 <= N - n + 1:
            right1 = bit.lower_bound(x + 1)
        if x + 2 <= N - n + 1:
            right2 = bit.lower_bound(x + 2)

        ans += ((left1 - left2) * (right1 - i) + (right2 - right1) * (i - left1)) * n


    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *P = list(map(int, read().split()))

    idx = [0] * (N + 1)
    for i, p in enumerate(P):
        idx[p] = i

    left = list(range(-1, N)) + [-1]
    right = list(range(1, N + 1)) + [N, N]

    ans = 0
    for n in range(1, N + 1):
        i = idx[n]
        l1 = left[i]
        l2 = left[l1]
        r1 = right[i]
        r2 = right[r1]

        ans += n * ((l1 - l2) * (r1 - i) + (r2 - r1) * (i - l1))

        left[r1] = l1
        right[l1] = r1

    print(ans)
    return


if __name__ == '__main__':
    main()
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    w = int(input().rstrip('\n'))
    print(("".join(s[::w])))


if __name__ == '__main__':
    slove()


# Optimized solution
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    w = int(readline())
    ans = []
    for i in range(0, len(s), w):
        ans.append(s[i])
    print(("".join(ans)))


if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

safe = set()
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]

        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]

        while digit[-1] == 0:
            digit = digit[:-1]

        if len(digit) == 1:
            safe.add(pro)
            continue

        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break

        if flag:
            safe.add(pro)

if safe:
    print((max(safe)))
else:
    print((-1))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]

        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]

        while digit[-1] == 0:
            digit = digit[:-1]

        if len(digit) == 1:
            ma = max(ma, pro)
            continue

        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break

        if flag:
            ma = max(ma, pro)

print(ma)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]

        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]

        while digit[-1] == 0:
            digit = digit[:-1]

        if len(digit) == 1:
            ma = max(ma, pro)
            continue

        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break

        if flag:
            ma = max(ma, pro)

print(ma)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

ma = -1
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]
        
        pre = pro % 10
        pro //= 10

        while pro:
            if pre - pro % 10 == 1:
                pre = pro % 10
                pro //= 10
            else:
                break

        if not pro:
            ma = max(ma, a[i] * a[j])
print(ma)
# Original solution
N, M = list(map(int, input().split()))

LL, MM = list(map(int, input().split()))
gate = [LL + i for i in range(MM-LL+1)]

for _ in range(M-1):
    LL, MM = list(map(int, input().split()))
    tmp = [LL + i for i in range(MM-LL+1)]
    gate = list(set(gate) & set(tmp))

print((len(gate)))


# Optimized solution
N, M = list(map(int, input().split()))

min_, max_ = list(map(int, input().split()))

for _ in range(M-1):
    LL, MM = list(map(int, input().split()))
    min_ = max(min_, LL)
    max_ = min(max_, MM)


if min_ <= max_:
    print((max_ - min_ + 1))
else:
    print((0))