stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;





int main() {

  string S;

  cin >> S;

  auto dp = vector< ll >(2019);

  ll ret = 0;

  for(auto &c : S) {

    auto dp2 = vector< ll >(2019);

    for(int i = 0; i < 2019; i++) {

      dp2[(i * 10 + (c - '0')) % 2019] += dp[i];

    }

    dp2[c - '0']++;

    ret += dp2[0];

    dp.swap(dp2);

  }

  cout << ret << endl;

}


// Optimized solution to the same problem (faster):
////D

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int a[2019],ans;

 

int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	string str;

	cin>>str;

	a[0]=1;

	ll t=0,cnt=1;

	for(int idx=str.length()-1;idx>=0;idx--){

		t=(t+cnt*(str[idx]-'0')%2019)%2019;

		//cout<<t<<endl;

		ans+=a[t];

		a[t]++;

		cnt=cnt*10%2019;

	}

	cout<<ans<<endl;

	return 0; 

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//codeforces

//

#include "bits/stdc++.h"

using namespace std;

int main(){

	char arr[200001];

	cin >> arr;



	long long int len = strlen(arr), nums[2020] = {1}, ans = 0;;

	int mods[len], dp[200005] = {0};;



	mods[len - 1] = 1, mods[len - 2] = 10;



	for(int i = len - 3; i >= 0; i--){

		mods[i] = (mods[i + 1] * 10) % 2019;

	}



	for(int i = len - 1; i >= 0; i--){

		dp[i] = (dp[i + 1] + ((arr[i] - '0') * mods[i])) % 2019;

		nums[dp[i]]++;

	}



	for(int i = 0; i < 2020; i++){

		ans += (nums[i] * (nums[i] - 1)) / 2;

	}



	cout << ans;

}


// Optimized solution to the same problem (faster):
//codeforces

//

#include "bits/stdc++.h"

using namespace std;

int main()

{

  string s;

  cin>>s;

  if(s.size()<4)

    cout<<0;

  else{

    int n=s.size();

    int arr[2200]={1};

    int mod[n+3]={0};

    mod[n-1]=1;

    mod[n-2]=10;

    for(int i=n-3; i>=0; i--)

      mod[i] = (mod[i+1]*10)%2019;

    int t=0;

    int p=0;

    for(int i=n-1; i>=0; i--){

      p = (p + (s[i]-'0')*mod[i])%2019;

      arr[p]++;

    }

    for(int i=0; i<2020; i++)

      t += (arr[i]*(arr[i]-1))/2;

    cout<<t;

  }

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

constexpr ll mod=1e9+7;



//return 10^n%2019

vector<int> vec(200030,1);



int main()

{

  for (auto i = 1; i < vec.size(); ++i)

  {

    vec[i]=(vec[i-1]*10)%2019;

  }



  string s;

  cin>>s;

  int n=s.size();

  vector<int> T(n,0);

  T[n-1]=(s[n-1]-'0')%2019;

  for (auto i = n-2; i >= 0; --i)

  {

    T[i]=((s[i]-'0')*vec[(n-i-1)]+T[i+1])%2019;

  }

  map<int,int> mp;

  for (auto i = 0; i < T.size(); ++i)

  {

    mp[T[i]]++;

  }

  mp[0]++;

  ll ans=0;

  for(const auto& e: mp) 

  {

    ans+=e.second*(e.second-1)/2;

  }

  cout<<ans<<endl;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

using ll=long long;

constexpr ll mod=1e9+7;



int main()

{



  string s;

  cin>>s;

  int n=s.size();

  int d=10;

  vector<int> T(n);

  T[n-1]=(s[n-1]-'0')%2019;

  for (int i = n-2; i >= 0; --i)

  {

    T[i]=((s[i]-'0')*d+T[i+1])%2019;

    d*=10;

    d%=2019;

  }

  map<int,int> mp;

  for (int i = 0; i < T.size(); ++i)

  {

    mp[T[i]]++;

  }

  mp[0]++;

  ll ans=0;

  for(const auto& e: mp) 

  {

    ans+=e.second*(e.second-1)/2;

  }

  cout<<ans<<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>  // clang-format off

using Int = long long;

#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)

#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)

struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;

#ifndef dump

#define dump(...)

#endif  // clang-format on



/**

 *    author:  knshnb

 *    created: Sun Apr 26 21:01:08 JST 2020

 **/



template <class T, class S> T make_vec(S x) { return x; }

template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {

    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));

}



const Int K = 2019;

signed main() {

    std::string s;

    std::cin >> s;

    Int n = s.size();

    auto dp = make_vec<Int>(2, K, 0);

    Int ans = 0;

    REP(i, n) {

        REP(j, K) {

            Int k = (10 * j + s[i] - '0') % K;

            dp[1][k] += dp[0][j];

        }

        dp[1][s[i] - '0'] += 1;

        ans += dp[1][0];

        std::swap(dp[0], dp[1]);

        std::fill(dp[1].begin(), dp[1].end(), 0);

    }

    std::cout << ans << std::endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>  // clang-format off

using Int = long long;

#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)

#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)

struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;

#ifndef dump

#define dump(...)

#endif  // clang-format on



/**

 *    author:  knshnb

 *    created: Tue Apr 28 20:35:37 JST 2020

 **/



const Int K = 2019;

signed main() {

    std::string s;

    std::cin >> s;

    Int n = s.size();

    std::vector<Int> cnt(K);

    cnt[0] = 1;

    Int pow = 1, cur = 0, ans = 0;

    for (Int i = n - 1; i >= 0; i--) {

        (cur += (s[i] - '0') * pow) %= K;

        (pow *= 10) %= K;

        ans += cnt[cur];

        cnt[cur]++;

    }

    std::cout << ans << std::endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;



int main() {

	string s;

	cin >> s;

	ll ans = 0;

	int n = s.size();

	vector<ll> v(2020);

	rep(i, n) {

		int now = (int) (s[i] - '0');

		vector<ll> n = v;

		rep(j, 2019) {

			if(v[j] == 0) continue;

			ll next = (j*10 + now)%2019;

			n[next] += v[j];

			n[j] -= v[j];

			// if(i<5) cout << i << " " << j << " " << next << " " << v[next] << " " << v[j] << endl;

		}

		v = n;

		v[now]++;

		ans += v[0];

	}

	// rep(i, 2019) cout << i << " :" << v[i] << endl;

	cout << ans << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;



int main() {

	string s;

	cin >> s;

	reverse(all(s));

	ll ans = 0;

	int n = s.size();

	const int mod = 2019;

	vector<int> tot(n+1), cnt(mod);

	int x = 1;

	rep(i, n) {

		if(i == 0) tot[i+1] = (int) (s[i] - '0');

		else tot[i+1] = (tot[i] + (int) (s[i] - '0')* x) % mod;

		x *= 10;

		x %= mod;

	}

	rep(i, n+1) cnt[tot[i]]++;

	rep(i, mod) ans += cnt[i]*(cnt[i]-1)/2;

	// rep(i, n+1) cout << tot[i] << " ";

	cout << ans << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef long long int ll;

typedef tree< ll, null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;



const ll mod = 1e9 + 7;



int main()

{

  ios_base::sync_with_stdio(false);

  cout.tie(0);cin.tie(0);



  string s;

  cin >> s;

  ll n = s.length();

  vector < ll > dp1(2019, 0), dp2(2019, 0);

  dp1[s[0] - '0'] = 1;

  ll ans = 0;

  for(int i = 1; i < n; i++){

    ll num = s[i] - '0';

    dp2[num] = 1;

    for(int j = 0; j < 2019; j++){

      dp2[(10 * j + num) % 2019] += dp1[j];

    }

    ans += dp2[0];

    dp1 = dp2;

    dp2.assign(2019, 0);

  }



  cout << ans << '\n';

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



typedef long long int ll;

typedef tree< ll, null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;



ll mod;



ll pwr(ll a, ll b){

  ll res = 1;

  while(b > 0){

    if(b & 1) res = (res * a) % mod;

    a = (a * a) % mod;

    b >>= 1;

  }

  return res;

}



int main()

{

  ios_base::sync_with_stdio(false);

  cout.tie(0);cin.tie(0);



  string s;

  cin >> s;

  ll n = s.length();



  mod = 2019;



  vector < ll > dp(2019, 0);

  ll x = 0, ans = 0;

  dp[0] = 1;

  for(int i = 0; i < n; i++){

    x = (x * 10 + (s[i] - '0')) % 2019;

    ll val = x * pwr(10, n - i - 1);

    val %= 2019;

    ans += dp[val];

    dp[val]++;

  }



  cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main(void) {

    string S;

    cin >> S;



    int64_t ans = 0;

    vector<int64_t> v0(2019), v1(2019);

    for(int i=0; i<S.size(); i++) {

        for(int j=0; j<2019; j++) {

            v1[(10*j + S[i] - '0')%2019] += v0[j];

        }

        v1[S[i] - '0']++;

        ans += v1[0];

        swap(v0, v1);

        fill(v1.begin(), v1.end(), 0);

    }



    cout << ans << endl;

    // vector<int[2019]> v(S.size()+1);

    // for(int i=0; i<S.size(); i++) {

    //     for(int j=0; j<2019; j++) {

    //         v[i+1][(j*10 + S[i] - '0')%2019] += v[i][j];

    //     }

    //     v[i+1][S[i] - '0']++;

    // }



    // int64_t ans = 0;

    // for(int i=0; i<=S.size(); i++) {

    //     ans += v[i][0];

    // }



    // cout << ans << endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main(void) {

    string S;

    cin >> S;



    int N = S.size();

    int P = 2019;

    vector<int> v(P);



    int t = 0;

    int ten = 1;

    for(int i=0; i<N; i++) {

        t += (S[N-1-i]-'0') * ten;

        ten *= 10;

        t %= P;

        ten %= P;

        v[t]++;

    }



    int ans = 0;

    for(auto e: v) {

        ans += e*(e-1)/2;

    }



    cout << ans + v[0] << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<vector>

#include<iostream>

#include<algorithm>

using namespace std;

bool Sort(long long a, long long b)

{

	return a > b;

}

int main()

{

	int num;

	while (cin >> num)

	{

		vector<long long> arr(num);

		for (int i = 0; i < num; i++)

			cin >> arr[i];

		sort(arr.begin(), arr.end(), Sort);



		long long a = 0, b = 0, temp = arr[0];

		for (int i = 1; i < num; i++)

		{

			if (temp == arr[i])

			{

				if (a < arr[i])

				{

					a = arr[i];

				}

				else if (b < arr[i])

				{

					b = arr[i];

				}

				temp = -1;

			}

			else temp = arr[i];

		}

		cout << a*b << endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[1000000];

int main()

{

    int n;

    while (~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

        {

            int te;

            scanf("%d",&a[i]);

        }

        if(n<4)

        {

            printf("0\n");

            continue;

        }

        sort(a,a+n);

        int c=0;

        int flag=0;

        int k[3];

        for(int i=n-2; i>=0; i--)

        {

            if(a[i+1]==a[i])

            {

                k[c]=a[i];

                i--;

                c++;

            }

            if(c==2)

            {

                break;

            }

            if(i==0)

            {

                printf("0\n");

                flag=1;

                break;

            }

        }

        if(!flag)

        {

            long long r;

            r=k[0]*k[1];

            printf("%lld\n",r);

//            printf("%d×%d rectangle can be formed.\n",k[1],k[0]);

        }

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define maxn 100005

using namespace std;

ll n;

ll a[maxn];

bool compare(ll x,ll y)

{

    return x>y;

}

int main()

{

    while(~scanf("%lld",&n))

    {

        ll i;

        for(i=0;i<n;i++)

            scanf("%lld",&a[i]);

        sort(a,a+n,compare);

        ll b[3];int step=0;

        b[0]=0;b[1]=0;b[2]=0;

        for(i=0;i<n-1;i++)

        {

            if(a[i]==a[i+1])

            {

                b[++step]=a[i];

                i++;

                if(step==2) break;

            }

        }

        printf("%lld\n",b[1]*b[2]);

    }

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<algorithm>

using namespace std;

int a[1000000];

int main()

{

    int n;

    while (~scanf("%d",&n))

    {

        for(int i=0; i<n; i++)

        {

            int te;

            scanf("%d",&a[i]);

        }

        if(n<4)

        {

            printf("0\n");

            continue;

        }

        sort(a,a+n);

        int c=0;

        int flag=0;

        int k[3];

        for(int i=n-2; i>=0; i--)

        {

            if(a[i+1]==a[i])

            {

                k[c]=a[i];

                i--;

                c++;

            }

            if(c==2)

            {

                break;

            }

            if(i==0)

            {

                printf("0\n");

                flag=1;

                break;

            }

        }

        if(!flag)

        {

            long long r;

            r=k[0]*k[1];

            printf("%lld\n",r);

//            printf("%d×%d rectangle can be formed.\n",k[1],k[0]);

        }

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <map>

#include <algorithm>

using namespace std;

typedef long long ll;

int main()

{

	int n;

	while (~scanf("%d", &n))

	{

		map<ll, int> m;

		ll x, pre = -1, maxn = -1, squ = -1;

		for (int i = 0; i < n; i++)

		{

			scanf("%lld", &x);

			m[x]++;

		}

		for (map<ll,int>::iterator it = m.begin(); it!=m.end(); it++)

		{

			if (it->second>1&&it->first>maxn)

			{

				pre = maxn;

				maxn=it->first;

			}

			if (it->second>3&&it->first>squ) squ = it->first;

		}

		ll rec = maxn*pre, squre = squ*squ;

		if ((~maxn||~pre)||~squ) printf("%lld\n", rec>squre?rec:squre);

		else printf("0\n");

	}

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<algorithm>

#include<math.h>

#define maxn 100005

const double INF=0xfffff;

using namespace std;

long long num[maxn];

int main()

{

  int n;

  long long flag1,flag2,flag3;

  int flag;

  while(scanf("%d",&n)!=EOF)

  {

  	flag1=-1;

  	flag2=-1;

  	flag=0;

    for(int i=0;i<n;i++)

    scanf("%d",&num[i]);

    sort(num,num+n);

    for(int i=n-2;i>=0;i--)

    {

    	if(num[i]==num[i+1]&&flag1==-1)

    		{

    			flag1=num[i];

    			flag2=i;

    		}

    	else if(num[i]==num[i+1]&&i<flag2-1)

    		{

    			flag=1;

    			flag3=num[i];

    			break;

    		}

    		

    }

    if(flag==0)

    	printf("0\n");

    	else

    		printf("%lld\n",flag1*flag3);

  }

   return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <map>

#include <cmath>

#include <queue>

#include <numeric>

#include <climits>

#include <iterator>

#include <iomanip>

#include <stack>

#include <bitset>

#include <functional>

using namespace std;

const constexpr int INF = 1e9;

//typedef std::pair<std::string,double> P;



typedef long long ll;

typedef vector<int> VI;



#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)



//グラフの隣接リスト

VI g[200010];

//頂点の入次数を管理

int h[100010];

ll N;



int a[200010];

ll sum[200010];

signed main(void) {

    cin >> N;

    REP(i, N) cin >> a[i];

    sort(a, a+N);

    vector<int> v;

    for(int i=N-1; i>=1; --i){

        if(v.size()==2) break;

        if(a[i]==a[i-1]) {

            v.push_back(a[i]);

            --i;

        }

    }

    if(v.size()==2) cout << (long long)v[0]*v[1] << endl;

    else cout << 0 << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include <vector>

#include <algorithm>

#include <string>

using namespace std;



int main(){

    int N; cin >> N;

    vector<int> v;

    int cnt4=0, cnt2=0;

    for(int i=0; i<N; ++i){

        int a; cin >> a;

        v.push_back(a);

    }

    sort(v.rbegin(), v.rend());

    long long ans=0;

    int cnt=0;

    for(int i=0; i<N-1; ++i){

        if(v[i]==v[i+1]){

            if(ans==0) ans =1;

            ans *= v[i];

            cnt++;

            i+=1;

        }

        if(cnt==2) break;

    }

    cout << ans << endl;

    

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;

int f[1000000];

int main(){

//	freopen("j.txt","r",stdin);

	int n;

	cin>>n;

	memset(f,0,sizeof(f));

	for (int i=1;i<=n;i++)

		cin>>f[i];

	sort(f+1,f+1+n);

	int flag=0,max1=0,max2=0;

	for (int i=n-1;i>=1;i--)

		if (f[i]==f[i+1] && !flag){

			max1=f[i];

			flag=1;

		} else if (f[i]==f[i+1] && flag){

			if (f[i]==f[i-1] && f[i]==max1) {

				max2=f[i];

				break;

			}

				else if (f[i]!=max1){

					max2=f[i];

					break;

				} 

		}

    long long s;

	s=(long long)max1*(long long)max2;

	//cout<<max1<<" "<<max2<<endl;

	cout<<s<<endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,tot,ans1,ans2,a[N];

int main(){

	n=read();

	rep(i,1,n) a[i]=read();

	sort(a+1,a+1+n);

	for (ll l=1,r=1;l<=n;l=++r){

		while (a[l]==a[r+1]) ++r;

		if (r-l+1>=2) ans2=ans1,ans1=a[l];

		if (r-l+1>=4) ans2=ans1,ans1=a[l];

	}

	printf("%lld",ans1*ans2);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #include <map>

    #include <set>

    #include <cmath>

    #include <queue>

    #include <stack>

    #include <cstdio>

    #include <string>

    #include <vector>

    #include <cstdlib>

    #include <cstring>

    #include <sstream>

    #include <iostream>

    #include <algorithm>

    #include <functional>

    using namespace std;

    #define MX 100000

    #define ll long long

    bool cmd(ll a,ll b){

    	return a>b;

    }

    int main(){

    	ll	 N,A[110000];

    	cin>>N;

    	for(int i=0;i<N;i++){

    		scanf("%d",&A[i]);

    	}

    	sort(A,A+N,cmd);

    	int flag=0;

    	int n=0;

    	ll tp1,tp2,sum;

    	for(int i=0;i<N;i++){

    		if(A[i]==A[i+1])

    		{

    			i++;

    			n++;

    			if(n==1)

    			tp1=A[i];

    			else{

    				sum=tp1*A[i];

    				cout<<sum;

    				return 0;

    			}

    		}

    	}

    	cout<<"0";

    	return 0;

    }

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,tot,ans1,ans2,a[N];

int main(){

	n=read();

	rep(i,1,n) a[i]=read();

	sort(a+1,a+1+n);

	for (ll l=1,r=1;l<=n;l=++r){

		while (a[l]==a[r+1]) ++r;

		if (r-l+1>=2) ans2=ans1,ans1=a[l];

		if (r-l+1>=4) ans2=ans1,ans1=a[l];

	}

	printf("%lld",ans1*ans2);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstring>

#include <algorithm>

#include <cstdio>

#include <set>

#include <vector>

using namespace std;

int main()

{

    int n;

    while(scanf("%d",&n)!=EOF)

    {

        set<int>st;

        vector<int>v;

        for(int i=0;i<n;i++)

        {

           int a;

           cin>>a;

           if(st.count(a))

           {

               st.erase(a);

               v.push_back(a);

           }

           else

           {

               st.insert(a);

           }

        }



        sort(v.begin(),v.end());



        if(v.size()<2)

        {

            printf("0\n");

        }

        else

        {

            int num=(int)v.size();

            printf("%lld\n",1ll*(v[num-1]) *(v[num-2]));

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,tot,ans1,ans2,a[N];

int main(){

	n=read();

	rep(i,1,n) a[i]=read();

	sort(a+1,a+1+n);

	for (ll l=1,r=1;l<=n;l=++r){

		while (a[l]==a[r+1]) ++r;

		if (r-l+1>=2) ans2=ans1,ans1=a[l];

		if (r-l+1>=4) ans2=ans1,ans1=a[l];

	}

	printf("%lld",ans1*ans2);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 100020

#define ll long long

using namespace std;

inline ll read(){

	ll x=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());

	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return f?x:-x;

}

map<ll, bool> mp;

std::vector<ll> res;

int main(int argc, char const *argv[]) {

	int n = read();

	for (int i = 1; i <= n; i++) {

		ll x = read();

		if (mp[x]) res.push_back(x), mp[x] = 0;

		else mp[x] = 1;

	}

	sort(res.begin(), res.end());

	if (res.size() < 2) return puts("0")&0;

	else cout << res[res.size()-1] * res[res.size()-2] << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

#define N 100005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,tot,ans1,ans2,a[N];

int main(){

	n=read();

	rep(i,1,n) a[i]=read();

	sort(a+1,a+1+n);

	for (ll l=1,r=1;l<=n;l=++r){

		while (a[l]==a[r+1]) ++r;

		if (r-l+1>=2) ans2=ans1,ans1=a[l];

		if (r-l+1>=4) ans2=ans1,ans1=a[l];

	}

	printf("%lld",ans1*ans2);

}

// Fastest known solution for this problem: