Result: Accepted
Time: 162ms
Memory: 7128kB
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
#define maxn 100010
#define ll long long
#define mm(a,b) memset(a,b,sizeof(a))
int n;
ll a[maxn];
map<int,int>m;
int main()
{
cin>>n;
for(int i=0;i<n;++i)
{
scanf("%lld",&a[i]);
m[a[i]]=1;
}
sort(a,a+n);
n=unique(a,a+n)-a;
ll ans=a[n-1];
for(int i=n-1;i>0;--i)
{
for(int j=i-1;a[j]+a[i]>ans;--j)
{
if(a[i]%a[j]&&a[j]%a[i]) {ans=a[i]+a[j]; break;}
}
}
cout<<ans;
}