stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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]);

}

// 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>

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;

}

// 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>

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;

}


// Optimized solution to the same problem (faster):
#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;

}


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


#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// 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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


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



using namespace std;



#define int long long



typedef pair<int,int> pii;



const int N = 1e5 + 100;



int d[N], sz[N], a[N];

vector<int> adj[N];

vector<pii> ans;

pii b[N];

int n, mx, val;



bool cmp(int x, int y) {

	return d[x] > d[y];	

}



inline int getPar(int v) {

	int hp = d[v] - n + 2 * sz[v];

	auto tmp = lower_bound(b, b + n, pii(hp, 0)) - b;

	if (b[tmp].first != hp) {

		cout << -1;

		exit(0);

	}

	return b[tmp].second;

}



int dfs(int v) {

	int res = 0;

	for (auto u : adj[v])

		res += dfs(u) + sz[u];

	return res;

}



int32_t main() {

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n;

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

		cin >> d[i];

		b[i] = {d[i], i};

		a[i] = i;

		sz[i] = 1;

	}

	sort(b, b + n);

	sort(a, a + n, cmp);

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

		int v = a[i];

		int p = getPar(v);

		sz[p] += sz[v];

		ans.push_back({v, p});

		adj[p].push_back(v);

		if (2 * sz[v] > n)

			return cout << -1, 0;

	}

	int root = a[n - 1];

	if (dfs(root) != d[root])

		return cout << -1, 0;

	for (auto e : ans)

		cout << e.first + 1 << " " << e.second + 1 << '\n', 0;

}

// Optimized solution to the same problem (faster):
#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;

}


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

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<map>

#include<vector>

#define pb push_back



typedef long long LL;



const int N=100005;



int n,size[N],id[N],ans1[N],ans2[N];

LL tot,a[N];

std::map<LL,int> num;

std::vector<int> vec[N];



bool cmp(int x,int y)

{

	return a[x]>a[y];

}



void dfs(int x,int fa,int d)

{

	tot+=(LL)d;

	for (int i=0;i<vec[x].size();i++)

		if (vec[x][i]!=fa) dfs(vec[x][i],x,d+1);

}



int main()

{

	scanf("%d",&n);

	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),num[a[i]]=i;

	for (int i=1;i<=n;i++) size[i]=1,id[i]=i;

	std::sort(id+1,id+n+1,cmp);

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

	{

		int x=id[i];LL w=a[x]-(n-size[x])+size[x];

		if (!num[w]||w>=a[x]) {puts("-1");return 0;}

		int y=num[w];

		ans1[i]=x;ans2[i]=y;

		vec[x].pb(y);vec[y].pb(x);

		size[y]+=size[x];

	}

	dfs(id[n],0,0);

	if (tot!=a[id[n]]) {puts("-1");return 0;}

	for (int i=1;i<n;i++) printf("%d %d\n",ans1[i],ans2[i]);

	return 0;

}

// Optimized solution to the same problem (faster):
#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;

}


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

#include<bits/stdc++.h>

#define int long long

using namespace std;

typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int n, si[maxn];

int sum = 0;

vector<int> e[maxn];

pii d[maxn];



void impossible() {

	cout << -1;

	exit(0);

}



void dfs(int u, int x) {

	sum += x;

	for(int i = 0; i < e[u].size(); i++) {

		dfs(e[u][i], x + 1);

	}

}



int32_t main() {

	cin >> n;

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

		int a;

		cin >> a;

		d[i] = {a, i};

	}

	sort(d, d + n);

	reverse(d, d + n);

	

	vector <pii> k (d, d + n);

	

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

		int leaf = d[q].second;

		int parD = d[q].first - (n - (2 * (si[leaf] + 1)));

		auto it = lower_bound(k.rbegin(), k.rend(), pii(parD, 0));

//		cout << "PAR : " <<it->first << " : " << parD << '\n';

		if(it -> first != parD) {

//			cerr << "AVALI\n";

			impossible();

		}

		int par = it -> second;

		si[par] += si[leaf] + 1;

		if((si[leaf] + 1) * 2 > n) {

//			cout << "DOVOMI\n";

			impossible();

		}

		//SEVOMI HAM MISHE D[I] ROOT OK E ?

		e[par].push_back(leaf);

	}

	int D = d[n - 1].second;

	dfs(D, 0);

	if(sum != d[n - 1].first)

		impossible();

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

		for(int j = 0; j < e[i].size(); j++)

			cout << i + 1 << " " << e[i][j] + 1 <<'\n';

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)



const int N(1e5 + 10);

struct edge { int x, y; } e[N];

struct node { long long d; int id; } a[N];

inline int operator < (const node &l, const node &r)

	{ return l.d < r.d; }

int n, size[N], cnt;



int main()

{

	scanf("%d", &n);

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

		scanf("%lld", &a[i].d), a[i].id = i, size[i] = 1;

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

	long long dis = 0, d;

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

	{

		d = a[i].d - n + (size[i] << 1), p = std::lower_bound(a + 1, a + n + 1, (node) {d, 0}) - a;

		if (a[p].d != d) return puts("-1"), 0;

		e[++cnt] = (edge) {a[i].id, a[p].id}, size[p] += size[i], dis += size[i];

	}

	if (dis != a[1].d) puts("-1");

	else for (int i = 1; i < n; i++) printf("%d %d\n", e[i].x, e[i].y);

	return 0;

}


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

#include<bits/stdc++.h>

#define int long long

using namespace std;

typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int n, si[maxn];

int sum = 0;

vector<int> e[maxn];

pii d[maxn];



void impossible() {

	cout << -1;

	exit(0);

}



void dfs(int u, int x) {

	sum += x;

	for(int i = 0; i < e[u].size(); i++) {

		dfs(e[u][i], x + 1);

	}

}



int32_t main() {

	scanf("%lld", &n);

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

		int a;

		scanf("%lld", &a);

		d[i] = {a, i};

	}

	sort(d, d + n);

	reverse(d, d + n);

	

	vector <pii> k (d, d + n);

	

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

		int leaf = d[q].second;

		int parD = d[q].first - (n - (2 * (si[leaf] + 1)));

		auto it = lower_bound(k.rbegin(), k.rend(), pii(parD, 0));

//		cout << "PAR : " <<it->first << " : " << parD << '\n';

		if(it -> first != parD) {

//			cerr << "AVALI\n";

			impossible();

		}

		int par = it -> second;

		si[par] += si[leaf] + 1;

		if((si[leaf] + 1) * 2 > n) {

//			cout << "DOVOMI\n";

			impossible();

		}

		//SEVOMI HAM MISHE D[I] ROOT OK E ?

		e[par].push_back(leaf);

	}

	int D = d[n - 1].second;

	dfs(D, 0);

	if(sum != d[n - 1].first)

		impossible();

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

		for(int j = 0; j < e[i].size(); j++) {

			printf("%lld %lld\n", i + 1, e[i][j] + 1);

		}

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)



const int N(1e5 + 10);

struct edge { int x, y; } e[N];

struct node { long long d; int id; } a[N];

inline int operator < (const node &l, const node &r)

	{ return l.d < r.d; }

int n, size[N], cnt;



int main()

{

	scanf("%d", &n);

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

		scanf("%lld", &a[i].d), a[i].id = i, size[i] = 1;

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

	long long dis = 0, d;

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

	{

		d = a[i].d - n + (size[i] << 1), p = std::lower_bound(a + 1, a + n + 1, (node) {d, 0}) - a;

		if (a[p].d != d) return puts("-1"), 0;

		e[++cnt] = (edge) {a[i].id, a[p].id}, size[p] += size[i], dis += size[i];

	}

	if (dis != a[1].d) puts("-1");

	else for (int i = 1; i < n; i++) printf("%d %d\n", e[i].x, e[i].y);

	return 0;

}


// Fastest known solution for this problem: