Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            for j in range(2*i, N, i):
                sieve[j] = 0
            P.append(i)
    return P

P = primes(32000)
D = defaultdict(list)

for a in A:
    for p in P:
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt:
            D[p].append(cnt)
    if a > 1:
        D[a].append(1)

D = {k:[0]*(len(v) == N-1) + sorted(v) for k, v in D.items() if len(v) >= N-1}

ori = 1
for k, v in D.items():
    ori *= k**v[0]

ans = max(ori, 1)
for a in A:
    tmp = 1 * ori
    for p in D.keys():
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt == D[p][0]:
            tmp *= p**(D[p][1] - D[p][0])
    ans = max(ans, tmp)
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            for j in range(2*i, N, i):
                sieve[j] = 0
            P.append(i)
    return P

P = set(primes(32000))
D = defaultdict(list)
C = set()
for a in A:
    removes = []
    for p in P:
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt:
            D[p].append(cnt)
        else:
            if p in C:
                removes.append(p)
            else:
                C.add(p)
    P = P - set(removes)
    if a > 1:
        D[a].append(1)

D = {k:[0]*(len(v) == N-1) + sorted(v) for k, v in D.items() if len(v) >= N-1}

ori = 1
for k, v in D.items():
    ori *= k**v[0]

ans = max(ori, 1)
for a in A:
    tmp = 1 * ori
    for p in D.keys():
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt == D[p][0]:
            tmp *= p**(D[p][1] - D[p][0])
    ans = max(ans, tmp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            for j in range(2*i, N, i):
                sieve[j] = 0
            P.append(i)
    return P

P = primes(32000)
D = defaultdict(list)

for a in A:
    for p in P:
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt:
            D[p].append(cnt)
    if a > 1:
        D[a].append(1)

D = {k:[0]*(len(v) == N-1) + sorted(v) for k, v in D.items() if len(v) >= N-1}

ori = 1
for k, v in D.items():
    ori *= k**v[0]

ans = max(ori, 1)
for a in A:
    tmp = 1 * ori
    for p in D.keys():
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt == D[p][0]:
            tmp *= p**(D[p][1] - D[p][0])
    ans = max(ans, tmp)
print(ans)
            

Fixed submission:
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            for j in range(2*i, N, i):
                sieve[j] = 0
            P.append(i)
    return P

P = set(primes(32000))
D = defaultdict(list)
C = set()
for a in A:
    removes = []
    for p in P:
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt:
            D[p].append(cnt)
        else:
            if p in C:
                removes.append(p)
            else:
                C.add(p)
    P = P - set(removes)
    if a > 1:
        D[a].append(1)

D = {k:[0]*(len(v) == N-1) + sorted(v) for k, v in D.items() if len(v) >= N-1}

ori = 1
for k, v in D.items():
    ori *= k**v[0]

ans = max(ori, 1)
for a in A:
    tmp = 1 * ori
    for p in D.keys():
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt == D[p][0]:
            tmp *= p**(D[p][1] - D[p][0])
    ans = max(ans, tmp)
print(ans)