Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

ans = 0
for i in range(N):
    new_list = A[:i] + A[i+1:]
    ans = max(ans, gcd_list(new_list))

print(ans)

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

gcd_front = gcd(A[0], A[1])
gcd_front_list = [A[0],gcd_front, ]
for i in range(2, N):
    gcd_front = gcd(gcd_front, A[i])
    gcd_front_list.append(gcd_front)

gcd_rear = gcd(A[N-1], A[N-2])
gcd_rear_list = [A[N-1], gcd_rear, ]

for i in range(N-3, -1, -1):
    gcd_rear = gcd(gcd_rear, A[i])
    gcd_rear_list.append(gcd_rear)

ans = 0

for i in range(N):
    if i == 0:
        ans = max(ans, gcd_rear_list[-2])
    if i == N-1:
        ans = max(ans, gcd_front_list[-2])   

    ans = max(ans, gcd(gcd_front_list[i-1],gcd_rear_list[N-2-i]))
    
print(ans)
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) 


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

index = 0
for i in range(len(A)):
    for j in range(len(B)):
        AB[index] = A[i] + B[j]
        index += 1

AB = sorted(AB, key = lambda x:-x)
AB = AB[0:3010]

ABC = [0] * (3010 * Z)
index = 0

for i in AB:
    for j in range(len(C)):
        if j > 3010:
            break
        ABC[index] = i + C[j]
        index += 1

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0,K):
    print(ABC[i])

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split())) 


A = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

ABC = []

for i in range(X):
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[k])

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0, K):
    print(ABC[i])
### BUGGY CODE ###

import sys, bisect
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def lis(a, colored):
    L = []
    L_idx = []
    ret = []
    for i, e in enumerate(a):
        if not colored[i]:
            idx = bisect.bisect_left(L, e)
            if idx==len(L):
                if len(L)>0:
                    ret.append(L_idx[-1])
                L.append(e)
                L_idx.append(i)
            else:
                idx = max(idx, 0)
                L[idx] = e
                L_idx[idx] = i
    ret.append(L_idx[-1])
    return ret

def resolve():
    N = I()
    A = [I()-1 for _ in range(N)]

    colored = [False]*N
    ans = 0
    while colored.count(False)>0:
        group = lis(A, colored)
        for i in group:
            colored[i] = True
        ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys, bisect
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def lis_(a):
    dp = [INF]*len(a)
    for i in a:
        dp[bisect.bisect_left(dp, i+1)] = i
    return bisect.bisect_left(dp, INF)

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    A = A[::-1]

    print(lis_(A))

if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

########ワーシャルフロイド法

def warshall_floyd(d):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


##############################
n, w, L = map(int, input().split())  # n:頂点数　w:辺の数

d = [[float("inf") for i in range(n)] for _ in range(n)]
# d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    d[x][y] = z
    d[y][x] = z
for i in range(n):
    d[i][i] = 0  # 自身のところに行くコストは０
d = warshall_floyd(d)

D = [[float("inf") for i in range(n)] for i in range(n)]

for i in range(n):
    for j in range(n):
        if i == j:
            D[i][j] = 0
        elif d[i][j] <= L:
            D[i][j] = 1
            D[j][i] = 1

D = warshall_floyd(D)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    if D[s][t] == float("inf"):
        print(-1)
    else:
        print(D[s][t] - 1)

### FIXED CODE ###

def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist

n,m,l = map(int,input().split())
inf = 10**18
dist = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    dist[i][i] = 0

for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    if c <= l:
        dist[a][b] = c
        dist[b][a] = c

dist = Warshall_Floyd(dist,n)
route = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1

route = Warshall_Floyd(route,n)

q = int(input())


for i in range(q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    print(route[s][t]-1 if route[s][t] < inf else -1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, x = map(int, input().split())
slimes = list(map(int, input().split()))

no_magic_cost = sum(slimes)


b_prev = [float('inf')]*n
for i in range(n):
    b_prev[i] = slimes[i]

# 魔法を唱える回数を固定
cost = float('inf')
for k in range(n):
    tmp = 0
    for i in range(0, n):
        b_prev[i] = min(b_prev[i], slimes[(i-k) % n])
        tmp += b_prev[i]
    cost = min(cost, tmp+k*x)
print(cost)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, x = map(int, input().split())
slimes = list(map(int, input().split()))

# 魔法を唱える回数を固定
cost = sum(slimes)
for k in range(n):
    slimes = [slimes[i-1] if slimes[i] > slimes[i-1] else slimes[i]
              for i in range(n)]
    cost = min(cost, sum(slimes)+(k+1)*x)
print(cost)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    edges = defaultdict(list)
    for _ in range(N):
        x, y = LI()
        edges[x].append(-y)
        edges[-y].append(x)
    visited = defaultdict(int)
    if max(len(li) for li in edges.values()) == 2 and N == 10 ** 5:
        return (N * N) - N
    def solve(v):
        visited[v] = 1
        ret = [v]
        for u in edges[v]:
            if not visited[u]:
                ret += solve(u)
        return ret
    ans = -N
    for node in edges:
        if not visited[node]:
            li = solve(node)
            m, p = 0, 0
            for z in li:
                if z < 0:
                    m += 1
                else:
                    p += 1
            ans += m * p
    return ans

print(main())

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx != 0 and gy != 0:  # merge
            if gx == gy:
                continue
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        m, p = 0, 0
        for xy in xys:
            if xy < 0:
                m += 1
            else:
                p += 1
        ans += m * p
    return ans

print(main())
### BUGGY CODE ###

n=int(input())
s=input()
r=[]
g=[]
b=[]

for i in range(len(s)):
    if s[i]=='R':
        r.append(i)
    elif s[i]=='G':
        g.append(i)
    elif s[i]=='B':
        b.append(i)
cnt=0
for _r in r:
    for _g in g:
        for _b in b:
            if _r<_g and _g<_b and (_g-_r!=_b-_g):
                cnt+=1
            elif _r<_b and _b<_g and (_g-_b!=_b-_r):
                cnt+=1
            elif _g<_b and _b<_r and (_r-_b!=_b-_g):
                cnt+=1
            elif _g<_r and _r<_b and (_b-_r!=_r-_g):
                cnt+=1
            elif _b<_r and _r<_g and (_g-_r!=_r-_b):
                cnt+=1
            elif _b<_g and _g<_r and (_r-_g!=_g-_b):
                cnt+=1
print(cnt)



### FIXED CODE ###

n=int(input())
s=input()
c=s.count
m=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      m-=1
print(m)
### BUGGY CODE ###

while 1:
    k=input().split()
    n=int(k[0])
    x=int(k[1])
    if n==0 and x==0 :
        break
    m=0
    for i1 in range(1,n+1):
        for i2 in  range(1,n+1):
            for i3 in  range(1,n+1):
                if (i1!=i2 and i2!=i3) and (i3!=i1 and x==i1+i2+i3):
                    m+=1
    print(m//6)


### FIXED CODE ###

while 1:
    k=input().split()
    n=int(k[0])
    x=int(k[1])
    if n==0 and x==0 :
        break
    m=0
    for i1 in range(1,n-1):
        for i2 in  range(i1+1,n):
            for i3 in  range(i2+1,n+1):
                if (i1!=i2 and i2!=i3) and (i3!=i1 and x==i1+i2+i3):
                    m+=1
    print(m)
### BUGGY CODE ###

N = int(input())
S = input()
rgb = {"R": [0]*N, "B": [0]*N, "G": [0]*N}
rg_set = {("R", "G"), ("G", "R")}
rb_set = {("R", "B"), ("B", "R")}
for i in range(N):
    rgb["R"][i] += rgb["R"][i-1] + (1 if S[i] == "R" else 0)
    rgb["G"][i] += rgb["G"][i-1] + (1 if S[i] == "G" else 0)
    rgb["B"][i] += rgb["B"][i-1] + (1 if S[i] == "B" else 0)
ans = 0
for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            if (i+k)%2 == 0:
                j = (i+k)//2
                if (S[i], S[k]) in rg_set:
                    ans += rgb["B"][k] - rgb["B"][i] - (1 if S[j] == "B" else 0)
                elif (S[i], S[k]) in rb_set:
                    ans += rgb["G"][k] - rgb["G"][i] - (1 if S[j] == "G" else 0)
                else:
                    ans += rgb["R"][k] - rgb["R"][i] - (1 if S[j] == "R" else 0)
            else:
                if (S[i], S[k]) in rg_set:
                    ans += rgb["B"][k] - rgb["B"][i]
                elif (S[i], S[k]) in rb_set:
                    ans += rgb["G"][k] - rgb["G"][i]
                else:
                    ans += rgb["R"][k] - rgb["R"][i]
print(ans)


### FIXED CODE ###

N = int(input())
S = list(input())
R, G, B = [0]*N, [0]*N, [0]*N
rg_set = {("R", "G"), ("G", "R")}
rb_set = {("R", "B"), ("B", "R")}
for i in range(N):
    R[i] += R[i-1] + (1 if S[i] == "R" else 0)
    G[i] += G[i-1] + (1 if S[i] == "G" else 0)
    B[i] += B[i-1] + (1 if S[i] == "B" else 0)
ans = 0
for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            if (i+k)%2 == 0:
                j = (i+k)//2
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i] - (1 if S[j] == "B" else 0)
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i] - (1 if S[j] == "G" else 0)
                else:
                    ans += R[k] - R[i] - (1 if S[j] == "R" else 0)
            else:
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i]
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i]
                else:
                    ans += R[k] - R[i]
print(ans)
### BUGGY CODE ###

a,b,k = map(int, input().split())
for i in range(k):
  if a == 0 and b == 0:
    print(0,0)
    exit()
  if a>=1:
    a-=1
    continue
  elif b>=1:
    b-=1
print(a,b)

### FIXED CODE ###

a,b,k = map(int, input().split())
if a>=k:
  print(a-k,b)
elif k>=a+b:
  print(0,0)
else:
  print(0,str(b-k+a))
### BUGGY CODE ###

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

data = {}

for i in range(len(A)):
    a = A[i]
    if a in data.keys():
        data[a].append(i)
    else:
        data[a] = [i]


for i in range(Q):
    B, C = map(int, input().split())

    temp = data.get(B)

    if temp is None:
        print(sum(A))
        continue

    for j in temp:
        A[j] = C

    if C in data.keys():
        data[C].extend(temp)
        del data[B]
    else:
        data[C] = data[B]

        del data[B]

    print(sum(A))

### FIXED CODE ###

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

data = [0] * 100001

def my_sum(d):
    retval = 0

    for i in range(len(d)):
        if d[i] == 0:
            continue
        retval += d[i] * i
    return retval

for i in A:
    data[i] += 1

sum_val = my_sum(data)

for i in range(Q):
    B, C = map(int,input().split())

    sum_val = sum_val - (data[B] * B) + (data[B] * C)

    data[C] += data[B]
    data[B] = 0

    print(sum_val)
### BUGGY CODE ###

import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

max_str = ''

for i, a in enumerate(a_list):
    kouho_list = copy.copy(a_list)
    kouho_list.pop(i)
    max_str += '{}\n'.format(max(kouho_list))

print(max_str[:-1])


### FIXED CODE ###

import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

kouho_list = sorted(a_list)
max_n = max(kouho_list)
second_max_n = kouho_list[-2]

max_list = [str(max_n) if x != max_n else str(second_max_n) for x in a_list]
max_str = '\n'.join(max_list)

print(max_str)
### BUGGY CODE ###

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
Nx=len(F[0])
Ny=len(F[1])

        
#i番目の文字で，位置x [-N~N]につけるかどうか
dpx=[[False]*(2*N+1) for _ in range(Nx+1)]
dpy=[[False]*(2*N+1) for _ in range(Ny+1)]

dpx[0][N]=True
dpy[0][N]=True

if Nx>=1:
    dpx[1][N]=False
    dpx[1][N+F[0][0]]=True
    if s[0]=="T":
        dpx[1][N-F[0][0]]=True


for i in range(1,Nx):
    for j in range(2*N+1):
        if dpx[i][j]==1:
            jj=j+F[0][i]
            jjj=j-F[0][i]
            if jj<=(2*N):
                dpx[i+1][jj]=1
            if jjj>=0:
                dpx[i+1][jjj]=1
                
                
for i in range(Ny):
    for j in range(2*N+1):
        if dpy[i][j]==1:
            jj=j+F[1][i]
            jjj=j-F[1][i]
            if jj<=(2*N):
                dpy[i+1][jj]=1
            if jjj>=0:
                dpy[i+1][jjj]=1

if dpx[-1][N+x]==1 and dpy[-1][N+y]==1:
    print("Yes")
else:
    print("No")





### FIXED CODE ###

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

s=input()+"T"
N=len(s)
x,y=MI()

F=[[],[]]

temp=0
bit=0
for i in range(N):
    if s[i]=="F":
        temp+=1
    else:
        if temp!=0:
            F[bit].append(temp)
        bit=(bit+1)%2
        temp=0
        
XY=[set([0]), set([0])]
    
for bit in range(2):
    for i in range(len(F[bit])):
        temp=set([])
        a=F[bit][i]
        b=-a
        if bit==0 and i==0 and s[0]=="F":
            b=a
        for j in range(len(XY[bit])):
            aaa=XY[bit].pop()
            temp.add(aaa+a)
            temp.add(aaa+b)
        XY[bit]=temp
        
if (x in XY[0] ) and (y in XY[1] ):
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
c = a[0] + a[1]

t = 0

for ai in a[2:]:
    t = t ^ ai

bit_len = c.bit_length()+1

ans = 10 ** 18
# print(t)

for num in range(2 ** bit_len):
    a1 = 0
    a2 = 0
    for i in range(bit_len):
        # flag = 1
        if num & (1 << i):
            # ti = 1
            if t & (1 << i):
                a1 += 2 ** i
        else:
            if t & (1 << i):
                a2 += 2 ** i
            else:
                a1 += 2 ** i
                a2 += 2 ** i
    if a1 and a[1] <= a2 and a1 + a2 == c:
        ans = min(ans, abs(a1-a[0]))

if ans == 10 ** 18:
    print(-1)
else:
    print(ans)
            

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int, input().split()))
c = a[0] + a[1]

t = 0

for ai in a[2:]:
    t = t ^ ai

bit_len = c.bit_length()+1

if c < t:
    print(-1)
    sys.exit()

if (c-t) % 2:
    print(-1)
    sys.exit()

b1 = (c - t) // 2


a1 = b1
a2 = b1


if a1 > a[0]:
    print(-1)
    sys.exit()
    

for i in reversed(range(bit_len)):
    if t & (1 << i):
        if b1 & (1 << i):
            print(-1)
            sys.exit()
        if a1 + 2 ** i <= a[0]:
            a1 += 2 ** i

if a1 == 0:
    print(-1)
else:
    print(a[0]-a1)
### BUGGY CODE ###

import bisect
s = input()
t = input()

pos = [0]*len(t)
for i, c in enumerate(t):
    ind = [ii for ii, v in enumerate(s) if v == c]
    if not ind:
        print(-1)
        exit()
    pos[i] = ind

lens = len(s)
last = pos[0][0]
res = last + 1
addval = 0
for vals in pos[1:]:
    if vals[-1] <= last:
        addval = (lens - last - 1) + (vals[0] + 1)
        res += addval
        last = vals[0]
    val = vals[bisect.bisect_left(vals, last)]
    addval = val - last
    res += addval
    last = val

print(res)


### FIXED CODE ###

import collections
import bisect
s = input()
t = input()

dict_pos = collections.defaultdict(list) # dict of index 
for i, ch in enumerate(s, 1): 
    dict_pos[ch].append(i)

count_loop = 0
last_pos = -1
for ch in t:
    list_pos = dict_pos[ch]
    if len(list_pos) == 0:
        print(-1)
        quit()
    if list_pos[-1] <= last_pos:
        last_pos = list_pos[0]
        count_loop += 1
    else:
        last_pos = list_pos[bisect.bisect_right(list_pos, last_pos)]

print(count_loop * len(s) + last_pos)
### BUGGY CODE ###

N, K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
MOD = 10**9 + 7


def choose(ans):
    l = 1
    if ans < 0:
        if a_list[-1]*a_list[-2] >= a_list[0]*a_list[1]:
            l *= a_list.pop(0)
            l *= a_list.pop(0)
        else:
            l *= a_list.pop(-1)
            l *= a_list.pop(-1)
    else:
        if a_list[-1]*a_list[-2] >= a_list[0]*a_list[1]:
            l *= a_list.pop(-1)
            l *= a_list.pop(-1)
        else:
            l *= a_list.pop(0)
            l *= a_list.pop(0)
    return l % MOD


ans = 1
if K == 1:
    print(a_list[-1]%MOD)
    exit()
else:
    if K % 2 == 0:
        for _ in range(K//2):
            ans *= choose(ans)
    else:
        ans *= a_list.pop(-1)
        for _ in range((K-1)//2):
            ans *= choose(ans)

print(ans%MOD)

### FIXED CODE ###

"""
E.
"""
from functools import reduce
from collections import deque


def prod(x, y):
    return x * y % MOD

    
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
# abs_a_list = sorted(a_list, key=abs, reverse=True)
MOD = 10**9 + 7

if K%2 == 1:
    flg = True
    for a in a_list:
        if a >= 0:
            flg = False
            break
    if flg:
        print(reduce(prod, a_list[:K]))
        exit()

S = []
a_list = deque(a_list)
i = 0
while i < K:
    if len(a_list)>=2:
        if a_list[0]*a_list[1] > a_list[-1]*a_list[-2]:
            S.append(a_list.popleft())
            i += 1
        elif a_list[0]*a_list[1] <= a_list[-1]*a_list[-2] and i <= K-2:
            S.append(a_list.pop())
            S.append(a_list.pop())
            i += 2
        else:
            S.append(a_list.popleft())
            i += 1
    else:
        S.append(a_list.popleft())
        i += 1
        
ans = reduce(prod, S)
print(ans)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
A = [input() for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] == ".":
      dist = 10000
      for b in blacks:
        dist = min(dist, abs(b[0]-h)+abs(b[1]-w))
      ans = max(dist, ans)
print(ans)



### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
count = 0
while len(blacks) > 0:
  newblacks = deque([])
  while len(blacks) > 0:
    b = blacks.popleft()
    for y, x in zip((b[0]-1, b[0], b[0], b[0]+1), (b[1], b[1]-1, b[1]+1, b[1])):
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if A[y][x] == ".":
        newblacks.append((y, x))
      A[y][x] = "#"
  blacks = newblacks
  count += 1
print(count-1)