stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.3204960535125x):
#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);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#define For(i,j,k)	for(int i=j;i<=k;++i)

#define Dow(i,j,k)	for(int i=k;i>=j;--i)

#define ll long long

#define inf 1e8

using namespace std;

inline ll read()

{

	ll t=0,f=1;char c=getchar();

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

	while(c>='0'&&c<='9')	t=t*10+c-48,c=getchar();

	return t*f;

}

int n,a[200001],mx1,mx2;

int main()

{

	n=read();

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

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

	Dow(i,1,n)	if(a[i]==a[i-1])	{mx1=i;break;}

	Dow(i,1,mx1-2)if(a[i]==a[i-1])	{mx2=i;break;}

	printf("%lld",(ll)a[mx1]*a[mx2]);

}

// Faster C++ solution for the same problem (measured speedup: 5.229390606513597x):
#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);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

set<int> s;

int x,n;

vector<int> q;

int main()

{

	cin>>n;

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

	{

		cin>>x;

		if (s.count(x))

		{

			s.erase(x);

			q.push_back(x);

		}

		else

			s.insert(x);

	}

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

	if (q.size()>=2)

		cout<<(long long)q[0]*q[1];

	else

		cout<<0;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.33157472050971x):
#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);

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.02717998254793x):
#include <bits/stdc++.h>

#define int long long

using namespace std;

struct ppap{int x,w;}b[100010];

inline bool cmp(ppap a,ppap b){return a.x>b.x;}

int n,a[100010];

signed main()

{

	ios::sync_with_stdio(0);

	cin>>n;

	for(int i=1;i<=n;i++)cin>>a[i];

	sort(a+1,a+n+1);int cnt=0;

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

		b[++cnt].x=a[i];int j=i;

		while(a[j]==a[i])j++,b[cnt].w++;

		i=j;

	}

	sort(b+1,b+cnt+1,cmp);int ans=0,p=0,k;

	for(int i=1;i<=n;i++)if(b[i].w>1){

		if(p==0&&b[i].w>3){

			ans=b[i].x*b[i].x;break;

		}

		p++;if(p==1)k=b[i].x;

		else{

			ans=b[i].x*k;break;

		}

	}

	cout<<ans;

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.145210528012068x):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    int n,i=0,temp=0;

    scanf("%d",&n);

    unsigned long a[n],x[2];

    unsigned long long area;

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

    {

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

    }

    sort(a,a+n,greater<unsigned long>());

    i=0;

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

    {

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

        {

            x[temp]=a[i];

            temp++;

            i++;

        }



        if(temp==2)

            break;

    }

    if(temp==2)

    {

        area=x[0]*x[1];

        printf("%llu" , area);

    }

    else

        printf("0");









}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.147972876645991x):
#include<bits/stdc++.h>

using namespace std;



int arra[100001];



int main()

{

    int N,a,b,i,j;







    scanf("%d",&N);



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

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



    sort(arra,arra+N,greater<int>());



    bool a_found=false,b_found=false;



    for(i=0,j=1;j<N;i++,j++){



        if(arra[i]==arra[j]){



                a_found=true;



            a=arra[i];



            break;



        }

    }



    if(a_found){



        for(i=j+1,j=j+2;j<N;j++,i++){



            if(arra[i]==arra[j]){



                b_found=true;



                b=arra[i];



                break;



            }







        }



    }



      if((a_found==true)&&(b_found==true)){



        printf("%lld",(long long int)a*b);





      }





       else{



        printf("0");



       }



    return 0;



}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 100000;

vector<ll> a(MAX_N);



int main(void) {

    int n;

    cin >> n;

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

        cin >> a[i];

    }

    sort(a.begin(), a.end(), greater<int>());



    ll s = -1, t = -1, ans = 0LL; 

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

        if (s > 0 && a[i] == a[i+1]) {

            t = a[i];

            ans = s * t;

            break;

        }

        if (s < 0 && a[i] == a[i+1]) {

            s = a[i];

            i++;

        }

    }

    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.7062209204896166x):
#include <bits/stdc++.h>

#define rep(i,a,b) for(int i=a;i<(b);++i)

#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)

#define per(i,a,b) for(int i=(b);i>(a);--i)

#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)

#define pb push_back

#define mp make_pair

#define INF 2000000000

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

int dy[]={0, 0, 1, -1};

int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int lcm(int a,int b){return a/gcd(a, b)*b;}



ll n, a[100005];

int main() {

 ios::sync_with_stdio ( false );

 cin.tie ( 0 );

    cin >> n;

    rep(i, 0, n) cin >> a[i];

    sort(a, a+n, greater<int>());

    ll s = -1, t = -1;

    rep(i, 0, n-1) {

        if (s > 0 && a[i+1] == a[i]) {

            t = a[i];

            cout << s * t << endl;

            return 0;

        } else if (s < 0 && a[i+1] == a[i]) {

            s = a[i];

            i++;

        }

    }

    cout << 0 << endl;

    return 0;

}
// Slower C++ solution:


#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

typedef long long ll;

#define N 100010

using namespace std;

ll scope[N];

ll squ[2];

bool cmp(int x,int y)

{

    return x<y;

}

int main()

{

    int n;

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

    {

        memset(scope,0,sizeof(scope));

        int cnt=0;

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

        {

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

        }

        sort(scope,scope+n,cmp);

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

        {

            if(cnt==2)break;

            if(scope[i]==scope[i-1])

            {

                i--;

                squ[cnt]=scope[i];

                cnt++;

            }



        }

        if(cnt!=2)printf("0\n");

        else printf("%lld\n",squ[0]*squ[1]);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7930694919980423x):
#include <bits/stdc++.h>

 #define ll long long

 using namespace std;

 const int N = 110;

 map<int,int> mp;

 int main() {

     int n, x;

 

     cin >> n;

     int MAX1 = 0, MAX2 = 0;

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

        scanf("%d", &x);

        if(mp.count(x)) {

		            if(x > MAX1) {

               MAX2 = MAX1;

               MAX1 = x;

             } else if(x > MAX2) {

                 if(x == MAX1 && mp[x] >= 3) {

                     MAX2 = x;

                } else if(x < MAX1) MAX2 = x;

             }

         }

         mp[x] ++;

     }

     printf("%lld\n",1LL*MAX1*MAX2);

     return 0;

 }
// Slower C++ solution:


#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

typedef long long ll;

#define N 100010

using namespace std;

ll scope[N];

ll squ[2];

bool cmp(int x,int y)

{

    return x<y;

}

int main()

{

    int n;

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

    {

        memset(scope,0,sizeof(scope));

        int cnt=0;

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

        {

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

        }

        sort(scope,scope+n,cmp);

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

        {

            if(cnt==2)break;

            if(scope[i]==scope[i-1])

            {

                i--;

                squ[cnt]=scope[i];

                cnt++;

            }



        }

        if(cnt!=2)printf("0\n");

        else printf("%lld\n",squ[0]*squ[1]);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8054720854584199x):
#include<bits/stdc++.h>

using namespace std;

int read(){

	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();

	int kk=1,k=0;if (c=='-')kk=-1,c=getchar();

	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;

}int n,a[1000000],x,d;

int main(){

	n=read();for (int i=1;i<=n;i++)a[i]=read();

	sort(a+1,a+1+n);d=n;while (a[d]!=a[d-1]&&d>0)d--;

	x=a[d-1];d-=2;while (a[d]!=a[d-1]&&d>0)d--;if (d==0)puts("0");else cout<<1ll*a[d]*x<<endl;

}
// Slower C++ solution:


#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

typedef long long ll;

#define N 100010

using namespace std;

ll scope[N];

ll squ[2];

bool cmp(int x,int y)

{

    return x<y;

}

int main()

{

    int n;

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

    {

        memset(scope,0,sizeof(scope));

        int cnt=0;

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

        {

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

        }

        sort(scope,scope+n,cmp);

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

        {

            if(cnt==2)break;

            if(scope[i]==scope[i-1])

            {

                i--;

                squ[cnt]=scope[i];

                cnt++;

            }



        }

        if(cnt!=2)printf("0\n");

        else printf("%lld\n",squ[0]*squ[1]);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.942182392240898x):
#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<map>

#include<cstring>

#include<algorithm>

#define ll long long

#define Max(x,y) ((x) > (y) ? (x) : (y))

#define Min(x,y) ((x) < (y) ? (x) : (y))

#define mod 1000000007

#define N 100010

using namespace std;

inline int read(){

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

	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;

}



int n;

map<int,int> mp;

int a[N],tot;



bool cmp(int a,int b){

	return a > b;

}



int main(){

	n = read();

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

		int x = read();

		mp[x]++;

		if(mp[x] == 2){

			a[++tot] = x;

			mp[x] = 0;

		}

	}

	sort(a+1,a+tot+1,cmp);

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

	return 0;

}
// Slower C++ solution:


#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<iostream>

typedef long long ll;

#define N 100010

using namespace std;

ll scope[N];

ll squ[2];

bool cmp(int x,int y)

{

    return x<y;

}

int main()

{

    int n;

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

    {

        memset(scope,0,sizeof(scope));

        int cnt=0;

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

        {

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

        }

        sort(scope,scope+n,cmp);

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

        {

            if(cnt==2)break;

            if(scope[i]==scope[i-1])

            {

                i--;

                squ[cnt]=scope[i];

                cnt++;

            }



        }

        if(cnt!=2)printf("0\n");

        else printf("%lld\n",squ[0]*squ[1]);

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8165144009683145x):
#include<stdio.h>

#include<iostream>

#include<string.h>

#include<algorithm>

#include<map>

#include<vector>

#include<string>

#define ll long long

#define For(i,x,y)  for(ll i=x;i<=y;++i)

#define FOr(i,x,y)  for(ll i=x;i>=y;--i)

using namespace std;

inline ll read(){   ll x=0,f=1;char ch=getchar();   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; } 

inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  } 

inline void writeln(ll x){ write(x);   puts("");   }



const ll N=200010;

ll a[N],q[N],n,tot;

int main(){

	n=read();

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

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

	For(i,1,n)	if (a[i]==a[i+1])	q[++tot]=a[i],i++;

	writeln(q[tot]*q[tot-1]);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<cmath>

#include<algorithm>

#include<map>

#include<queue>

#include<deque>

#include<stack>

#define INF 0X3F3F3F3F

#define LL long long

#define SC(x) scanf("%d",&x)

#define SCC(x,y) scanf("%d%d",&x,&y)

#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)

#define FF(i,a,b) for(int i=a; i<=b; i++)

#define RR(i,a,b) for(int i=a; i>=b; i--)

#define FC(i,a,b) for(int i=a; i<b; i++)

#define SS(x) scanf("%s",x)

#define PR(x) printf("%d\n",x)

#define PRR(x,y) printf("%d%d\n",x,y)

#define CL(a,x) memset(a,x,sizeof(a))

#define MID int mid=((l+r)>>1)

#define lson x<<1,l,mid

#define rson x<<1|1,mid+1,r

#define _X sum[x]

#define _L sum[x<<1]

#define _R sum[x<<1|1]

#define IN freopen("in.txt","r",stdin)

#define OUT freopen("out.txt","w",stdout)

#define MAIN 10000010

#define MAXN 50010

using namespace std;

int n,m,a[MAXN];

map <int,int> mm;

int main()

{

    mm.clear();

    SC(n);

    FF(i,1,n)

    {

        SC(m);

        mm[m]++;

    }

    map <int,int>::iterator it;

    int f1=-1,f2=-1;

    for(it=mm.end();it!=mm.begin(); it--)

    {

        if(it->second>1)

        {

            if(f1==-1) f1=it->first,it->second-=2;

        }

        if(it->second>1)

        {

            if(f2==-1) f2=it->first,it->second-=2;

        }

        if(f1!=-1&&f2!=-1) break;

    }

    it=mm.begin();

    if(it->second>1)

    {

        if(f1==-1) f1=it->first,it->second-=2;

    }

    if(it->second>1)

    {

        if(f2==-1) f2=it->first,it->second-=2;

    }

    if(f1==-1||f2==-1) printf("0\n");

    else

    {

        LL ans=(LL)f1*(LL)f2;

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

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.214758547114429x):
#include <stdio.h>

#include <algorithm>

#include <string.h>

using namespace std;

typedef long long LL;

#define N 100005

LL a[N];



int main()

{

    int n, cnt = 0;

    LL ans = 1;

    scanf("%d", &n);

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

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

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

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

    {

        if (cnt == 2) break;

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

        {

            ans *= a[i];

            i--;

            cnt++;

        }

    }

    if (cnt == 2)

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

    else

        printf("0\n");



    return 0;

}
// Slower C++ solution:
// In the name of God



#include<bits/stdc++.h>



#define F first

#define S second

#define PB push_back

#define sz(s) int((s).size())

#define bit(n,k) (((n)>>(k))&1)



using namespace std;



typedef long long ll;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;



const int maxn=1e5+10,mod=1e9+7;

const ll inf=1e18;



pair<ll,int> p[maxn];

map<ll,vector<int> >mp;

int par[maxn],SZ[maxn];

vector<int>v[maxn];



pair<ll,int> dfs(int u,int par=-1){

    ll A=0;

    int B=1;

    for(int y:v[u]){

	if(y!=par){

	    pair<ll,int>p=dfs(y,u);

	    B+=p.S;

	    A+=p.F+p.S;

	}

    }

    return {A,B};

}



int main(){

    int n;cin>>n;

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

	cin>>p[i].F;

	p[i].S=i;

    }

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

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

	SZ[p[i].S]=1;

	if(mp.count(p[i].F)){

	    for(int id:mp[p[i].F]){

		par[id]=p[i].S;

		SZ[p[i].S]+=SZ[id];

	    }

	    mp.erase(p[i].F);

	}

	mp[p[i].F+2*SZ[p[i].S]-n].PB(p[i].S);

    }

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

	if(par[i]==0 && i!=p[1].S){

	    return cout<<-1<<endl,0;

	}

	else if(par[i]!=0){

	    v[par[i]].PB(i);

	}

    }

    if(dfs(p[1].S).F!=p[1].F){

	return cout<<-1<<endl,0;

    }

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

	if(i==p[1].S)continue;

	cout<<i<<" "<<par[i]<<"\n";

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.4425373938461914x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin>>n;

	vector<pair<long long,int>>e;

	map<long long,int>ret;

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

	{

		long long x;

		cin>>x;

		ret[x]=i;

		e.push_back({x,i});

	}

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

	long long x=e.back().first;

	vector<int>sz(n,1);

	vector<long long>dp(n,0);

	vector<pair<int,int>>ans;

	for(auto c:e)

	{

		if(c.first!=x)

		{

			if(sz[c.second]*2>=n)

			{

				cout<<-1<<endl;

				return 0;

			}

			long long need=c.first-(n-2*sz[c.second]);

			if(!ret.count(need))

			{

				cout<<-1<<endl;

				return 0;

			}

			int par=ret[need];

			dp[par]+=dp[c.second]+sz[c.second];

			sz[par]+=sz[c.second];

			ans.push_back({c.second+1,par+1}); 

		}

	}

	if(dp[e.back().second]!=x)

	{

		cout<<-1<<endl;

		return 0;

	}

	for(auto c:ans)

		cout<<c.first<<' '<<c.second<<endl;

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <vector>

#include <map>

using namespace std;

typedef long long ll;



const int MAXN = 1e5 + 10;

vector<pair<int, int> > edg;

pair<ll, int> d[MAXN];

vector<int> Mat[MAXN];

int n, cnt[MAXN];

map<ll, int> mp;

bool se[MAXN];

ll dist, dt;

int num;



void dfs(int v, int di) {

	se[v] = 1, num++;

	dist += di;

	for (int i = 0; i < Mat[v].size(); i++)

		if (!se[Mat[v][i]])

			dfs(Mat[v][i], di + 1);

}



int main() {

	cin >> n;

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

		cin >> d[i - 1].first;

		if (i == 1)

			dt = d[i - 1].first;

		mp[d[i - 1].first] = i;

		d[i - 1].second = i;

		cnt[i] = 1;

	}

	sort(d, d + n);

	reverse(d, d + n);

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

		int k = cnt[d[i].second];

		if (2 * k > n || mp.find(d[i].first + k - (n - k)) == mp.end())

			return cout << -1, 0;

		cnt[mp[d[i].first + k - (n - k)]] += k;

		edg.push_back({d[i].second, mp[d[i].first + k - (n - k)]});

		Mat[mp[d[i].first + k - (n - k)]].push_back(d[i].second);

		Mat[d[i].second].push_back(mp[d[i].first + k - (n - k)]);

	}

	dfs(1, 0);

	if (dist == dt && num == n && edg.size() == n - 1) {

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

			cout << edg[i].first << ' ' << edg[i].second << endl;

		return 0;

	}

	cout << -1;

}

// Faster C++ solution for the same problem (measured speedup: 3.4402390579697393x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

int main()

{

	ios::sync_with_stdio(false);

	int n;

	cin>>n;

	vector<pair<long long,int>>e;

	map<long long,int>ret;

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

	{

		long long x;

		cin>>x;

		ret[x]=i;

		e.push_back({x,i});

	}

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

	long long x=e.back().first;

	vector<int>sz(n,1);

	vector<long long>dp(n,0);

	vector<pair<int,int>>ans;

	for(auto c:e)

	{

		if(c.first!=x)

		{

			if(sz[c.second]*2>=n)

			{

				cout<<-1<<endl;

				return 0;

			}

			long long need=c.first-(n-2*sz[c.second]);

			if(!ret.count(need))

			{

				cout<<-1<<endl;

				return 0;

			}

			int par=ret[need];

			dp[par]+=dp[c.second]+sz[c.second];

			sz[par]+=sz[c.second];

			ans.push_back({c.second+1,par+1}); 

		}

	}

	if(dp[e.back().second]!=x)

	{

		cout<<-1<<endl;

		return 0;

	}

	for(auto c:ans)

		cout<<c.first<<' '<<c.second<<endl;

	return 0;

}