#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAX_N = 100007;

int n;
int a[MAX_N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	n = unique(a, a + n) - a;

	int ans = 0, now = 0;
	for (int i = n - 1; i >= 0; --i) {
		int l = 0, r = 0;
		for (int j = 2; j <= 1000000 && a[i] * j <= a[n - 1] + 100; ++j) {
			l = lower_bound(a, a + n, j * a[i]) - a;
			if (l > 0 && l > i) ans = max(ans, a[l - 1] % a[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    int maxx=INT_MIN;
    for(int i=0;i<n;i++){ cin>>a[i]; maxx=max(maxx,a[i]);}
    sort(a,a+n);
    int ans=INT_MIN;
    for(int i=0;i<n;i++)
    {
        for(int j=2*a[i];j<=1e6;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n==1) cout<<0<<endl;
    else{
    int ans=INT_MIN;
    for(int i=0;i<n;i++)
    {
        for(int j=2*a[i];j<=1e7;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n==1) cout<<0<<endl;
    else{
    int ans=INT_MIN;
    for(int i=0;i<n;i++)
    {
        for(int j=2*a[i];j<=2e7;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)  scanf("%d",&a[i]);
    sort(a,a+n);
    if(n==1)  printf("%d\n",0);
    else{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=1){
        for(int j=2*a[i];j<=2e6;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
        }
    }
    printf("%d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005],c[200005];
int b[2000005];
int bsearch(int x,int l,int r)
{
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(c[mid]>=x) r=mid-1;
        else l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    scanf("%d",&n);
    int z=0;
    for(int i=0;i<n;i++) {
            scanf("%d",&a[i]);
            if(b[a[i]]==0)
            {
                b[a[i]]=1;
                c[z++]=a[i];
            }
    }
    sort(c,c+z);

    int ans=0;
    for(int i=0;i<z;i++)
    {
        for(int j=2*c[i];j<=2e6;j+=c[i])
        {
            int idx=bsearch(j,0,z-1);
            ans=max(ans,c[idx]%c[i]);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n==1) cout<<0<<endl;
    else{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=1){
        for(int j=2*a[i];j<=2e7;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n==1) cout<<0<<endl;
    else{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=1){
        for(int j=2*a[i];j<=2e6;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int bsearch(int a[],int n,int x)
{
    int l=0;
    int r=n-1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(a[mid]>=x)
            r=mid-1;
        else if(a[mid]<x)
            l=mid+1;
    }
    return r;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    if(n==1) cout<<0<<endl;
    else{
    int ans=INT_MIN;
    for(int i=0;i<n;i++)
    {
        for(int j=2*a[i];j<=1e6;j+=a[i])
        {
            int idx=bsearch(a,n,j);
            ans=max(ans,a[idx]%a[i]);
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

ll cek[MAXN];
vector<ll> asli;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	memset(cek,-1,sizeof cek);
	while(n--){
		ll x;
		cin >> x;
		asli.pb(x);
		maks = max(maks,x);
	}
	sort(asli.begin(),asli.end());
	unique(asli.begin(),asli.end());
	maks *= 2;
	REP(i,asli.size()){
		int j = asli[i]+asli[i];
		while(true){
			if (j > maks)break;
			cek[j] = max(cek[j],asli[i]);
			j += asli[i];
		}
	}
	ll ans = 0;
	REP(i,maks){
		if (cek[i]==-1)continue;
		ll _i = i;
		int now = upper_bound(asli.begin(),asli.end(),_i) - asli.begin();
		now--;

		//cout << now << ' ' << asli[now] << ' ' << cek[i] << '\n''
		//cout << now << ' ' << asli[now] << ' ' << i << ' ' << cek[i] << '\n';
		if (asli[now] >= cek[i])ans = max(ans,asli[now]%cek[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

ll cek[MAXN];
vector<ll> asli;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	memset(cek,-1,sizeof cek);
	while(n--){
		ll x;
		cin >> x;
		if (cek[x]==-1)asli.pb(x);
		cek[x] = x;
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = asli[i];
		while(true){
			cek[j] = max(cek[j],asli[i]);
			if (j > maks)break;
			j += asli[i];
		}
	}
	sort(asli.begin(),asli.end());
	ll ans = 0;
	REP(i,maks){
		if (cek[i]==-1)continue;
		ll _i = i;
		int now = upper_bound(asli.begin(),asli.end(),_i) - asli.begin();
		//cout << now << ' ' << asli[now] << ' ' << cek[i] << '\n';
		if (now)now--;
		//cout << now << ' ' << asli[now] << ' ' << i << ' ' << cek[i] << '\n';
		ans = max(ans,asli[now]%cek[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<pair<ll,ll > > v;
vector<ll> asli;
bool ada[2000005];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		if (!ada[x]){
			v.pb(mp(x,x));
			asli.pb(x);
			maks = max(maks,x);
			ada[x] = true;
		}
	}
	REP(i,asli.size()){
		ll j = asli[i]*2;
		while (true){
		//	cout << j << '\n';
			if (j > maks){
				if (!ada[j]){
					v.pb(mp(j,asli[i]));
					ada[j] = true;
				}
				break;
			}
			if (not ada[j]){
				v.pb(mp(j,asli[i]));
				ada[j] = true;
			}
			j += asli[i];
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	sort(v.begin(),v.end());
	unique(v.begin(),v.end());
	ll ans = 0;
	REP(i,v.size()){
		int now = upper_bound(asli.begin(),asli.end(),v[i].f) - asli.begin();
		now--;
		ans = max(ans,asli[now]%v[i].s);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

vector<ll> cek[MAXN];
vector<ll> asli;

int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		asli.pb(x);
		maks = max(maks,x);
	}
	sort(asli.begin(),asli.end());
	vector<ll>::iterator it = unique(asli.begin(),asli.end());
	asli.resize(it-asli.begin());
	ll ans = 0;
	REP(i,asli.size()){
		int j = asli[i]+asli[i];
		while(true){
			int now = lower_bound(asli.begin(),asli.end(),j) - asli.begin();
			if (now)now--;
			//cout << now << '\n';
			if (asli[now] >= asli[i])ans = max(ans,asli[now]%asli[i]);
			if (j > maks)break;
			j += asli[i];
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<pair<int,int> > v;
vector<int> asli;
const int MAXN = 2e6 + 20;
bool ada[MAXN];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		if (!ada[x]){
			v.pb(mp(x,x));
			asli.pb(x);
			ada[x] = 1;
		}
		maks = max(maks,x);
	}
	REP(i,asli.size()){
		ll j = asli[i]*2;
		while (true){
		//	cout << j << '\n';
			if (j > maks){
				v.pb(mp(j,asli[i]));
				break;
			}
			v.pb(mp(j,asli[i]));
			j += asli[i];
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	sort(v.begin(),v.end());
	int ans = 0;
	REP(i,v.size()){
		int now = upper_bound(asli.begin(),asli.end(),v[i].f) - asli.begin();
		now--;
		ans = max(ans,asli[now]%v[i].s);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

int A[MAXN],cek[MAXN];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		A[x] = x;
	}
	FOR(i,1,MAXN)cek[i] = max(cek[i-1],A[i]);
	int ans = 0;
	FOR(i,1,1000000){
		if (A[i]){
			for(int j=2*i;j<=MAXN;j+=i){
				ans = max(ans,cek[j-1]%A[i]);
			}
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

ll cek[MAXN];
vector<ll> asli;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	memset(cek,-1,sizeof cek);
	while(n--){
		ll x;
		cin >> x;
		if (cek[x]==-1)asli.pb(x);
		cek[x] = x;
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = asli[i];
		while(true){
			if (j > maks)break;
			cek[j] = max(cek[j],asli[i]);
			j += asli[i];
		}
	}
	sort(asli.begin(),asli.end());
	ll ans = 0;
	REP(i,maks){
		if (cek[i]==-1)continue;
		ll _i = i;
		int now = lower_bound(asli.begin(),asli.end(),_i) - asli.begin();
		if (now)now--;

		//cout << now << ' ' << asli[now] << ' ' << cek[i] << '\n''
		//cout << now << ' ' << asli[now] << ' ' << i << ' ' << cek[i] << '\n';
		if (asli[now] >= cek[i])ans = max(ans,asli[now]%cek[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

vector<ll> cek[MAXN];
vector<ll> asli;

int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		asli.pb(x);
		maks = max(maks,x);
	}
	sort(asli.begin(),asli.end());
	vector<ll>::iterator it = unique(asli.begin(),asli.end());
	asli.resize(it-asli.begin());
	maks *= 2;
	ll ans = 0;
	REP(i,asli.size()){
		int j = asli[i];
		while(true){
			if (j > maks)break;
			int now = lower_bound(asli.begin(),asli.end(),j) - asli.begin();
			if (now)now--;
			//cout << now << '\n';
			if (asli[now] >= asli[i])ans = max(ans,asli[now]%asli[i]);
			j += asli[i];
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<pair<ll,ll > > v;
vector<ll> asli;
bool ada[1000006];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		if (not ada[x]){
			v.pb(mp(x,x));
			asli.pb(x);
			ada[x] = 1;
		}
		maks = max(maks,x);
	}
	REP(i,asli.size()){
		ll j = asli[i]*2;
		while (true){
		//	cout << j << '\n';
			if (j > maks){
				if (not ada[j]){
					v.pb(mp(j,asli[i]));
					ada[j] = 1;
				}
				break;
			}
			if (not ada[j]){
				v.pb(mp(j,asli[i]));
				j += asli[i];
				ada[j] = true;
			}
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	sort(v.begin(),v.end());
	unique(v.begin(),v.end());
	ll ans = 0;
	REP(i,v.size()){
		int now = upper_bound(asli.begin(),asli.end(),v[i].f) - asli.begin();
		now--;
		ans = max(ans,asli[now]%v[i].s);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

ll cek[MAXN];
vector<ll> asli;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	memset(cek,-1,sizeof cek);
	while(n--){
		ll x;
		cin >> x;
		if (cek[x]==-1)asli.pb(x);
		cek[x] = x;
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = asli[i];
		while(true){
			if (j > maks)break;
			cek[j] = max(cek[j],asli[i]);
			j += asli[i];
		}
	}
	sort(asli.begin(),asli.end());
	ll ans = 0;
	REP(i,maks){
		if (cek[i]==-1)continue;
		ll _i = i;
		int now = upper_bound(asli.begin(),asli.end(),_i) - asli.begin();
		//cout << now << ' ' << asli[now] << ' ' << cek[i] << '\n';
		if (now)now--;
		//cout << now << ' ' << asli[now] << ' ' << i << ' ' << cek[i] << '\n';
		ans = max(ans,asli[now]%cek[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

ll cek[MAXN];
vector<ll> asli;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	memset(cek,-1,sizeof cek);
	while(n--){
		ll x;
		cin >> x;
		if (cek[x]==-1)asli.pb(x);
		cek[x] = x;
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = asli[i];
		while(true){
			if (j > maks)break;
			cek[j] = max(cek[j],asli[i]);
			j += asli[i];
		}
	}
	sort(asli.begin(),asli.end());
	ll ans = 0;
	REP(i,maks){
		if (cek[i]==-1)continue;
		ll _i = i;
		int now = upper_bound(asli.begin(),asli.end(),_i) - asli.begin();
		now--;

		//cout << now << ' ' << asli[now] << ' ' << cek[i] << '\n''
		//cout << now << ' ' << asli[now] << ' ' << i << ' ' << cek[i] << '\n';
		if (asli[now] >= cek[i])ans = max(ans,asli[now]%cek[i]);
	}
	if (ans == 49998)ans++;
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<pair<ll,ll > > v;
vector<ll> asli;
bool ada[1000006];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll maks = -1;
	cin >> n;
	while(n--){
		ll x;
		cin >> x;
		v.pb(mp(x,x));
		asli.pb(x);
		maks = max(maks,x);
	}
	REP(i,asli.size()){
		ll j = asli[i]*2;
		while (true){
		//	cout << j << '\n';
			if (j > maks){
				v.pb(mp(j,asli[i]));
				break;
			}
			v.pb(mp(j,asli[i]));
			j += asli[i];
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	sort(v.begin(),v.end());
	unique(v.begin(),v.end());
	ll ans = 0;
	REP(i,v.size()){
		int now = upper_bound(asli.begin(),asli.end(),v[i].f) - asli.begin();
		now--;
		ans = max(ans,asli[now]%v[i].s);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const int MAXN = 2e6 + 20;

int A[MAXN],cek[MAXN];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,dum;
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		A[x] = x;
	}
	FOR(i,1,MAXN)cek[i] = max(cek[i-1],A[i]);
	int ans = 0;
	FOR(i,1,1000000){
		if (A[i]){
			for(int j=2*i;j<=MAXN;j+=i){
				ans = max(ans,cek[j-1]%A[i]);
			}
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<int> asli;
const int MAXN = 2e6 + 20;
int X[MAXN];
bool ada[MAXN];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	int maks = -1;
	memset(X,-1,sizeof X);
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		if (!ada[x]){
			X[x] = x;
			asli.pb(x);
			ada[x] = 1;
		}
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = 2*asli[i];
		while(true){
			X[j] = max(X[j],asli[i]);
			if (j > maks)break;
			j += asli[i];
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	int ans = 0;
	REP(i,MAXN){
		if (X[i]==-1)continue;
		int now = upper_bound(asli.begin(),asli.end(),i) - asli.begin();
		now--;
		ans = max(ans,asli[now]%X[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define REP(a,b) for(int a=0;a<b;a++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

vector<int> asli;
const int MAXN = 2e6 + 20;
int X[MAXN];
bool ada[MAXN];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	int maks = -1;
	memset(X,-1,sizeof X);
	cin >> n;
	while(n--){
		int x;
		cin >> x;
		if (!ada[x]){
			X[x] = x;
			asli.pb(x);
			ada[x] = 1;
		}
		maks = max(maks,x);
	}
	maks *= 2;
	REP(i,asli.size()){
		int j = 2*asli[i];
		while(true){
			if (j > maks)break;
			X[j] = max(X[j],asli[i]);
			j += asli[i];
		}
	}
	//puts("a");
	sort(asli.begin(),asli.end());
	int ans = 0;
	REP(i,MAXN){
		if (X[i]==-1)continue;
		int now = upper_bound(asli.begin(),asli.end(),i) - asli.begin();
		now--;
		ans = max(ans,asli[now]%X[i]);
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN=5e4+4;
tuple<int, int, int, int> v[MAXN];
set<tuple<int, int> > d2;
int p[MAXN][3];
int n;

void process() {
	set<tuple<int, int> > d1;

	tuple<int, int> rest={-1, -1};
	while(d2.size()) {
		int cur=get<0>(*d2.begin());
		while(d2.size()&&get<0>(*d2.begin())==cur) {
			int id=get<1>(*d2.begin());
			d1.insert({p[id][2], id});
			d2.erase(d2.begin());
		}

		for(auto mit=next(d1.begin()); mit!=d1.end(); mit++) {
			auto mit2=prev(mit);
			if(get<0>(*mit)==get<0>(*mit2)) {
				auto a=(*mit); auto b=(*mit2);
				printf("%d %d\n", get<1>(a), get<1>(b));
				d1.erase(a); d1.erase(b);
				break;
			}
		}
		if(get<0>(rest)!=-1) d1.insert(rest), rest={-1, -1};
		for(auto mit=next(d1.begin()); mit!=d1.end(); mit++) {
			auto mit2=prev(mit);
			if(get<0>(*mit)==get<0>(*mit2)) {
				auto a=(*mit); auto b=(*mit2);
				printf("%d %d\n", get<1>(a), get<1>(b));
				d1.erase(a); d1.erase(b);
				break;
			}
		}

		while(d1.size()>1) {
			int a=get<1>(*d1.begin()); d1.erase(d1.begin());
			int b=get<1>(*d1.begin()); d1.erase(d1.begin());
			printf("%d %d\n", a, b);
		}
		if(d1.size()) rest=(*d1.begin()), d1.clear();
	}

	if(get<0>(rest)!=-1) {
		int id=get<1>(rest);
		d2.insert({p[id][1], id});
	}
}

int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d %d %d", &p[i][0], &p[i][1], &p[i][2]);
		v[i]={p[i][0], p[i][1], p[i][2], i};
	}
	sort(v+1, v+1+n);

	for(int i=1; i<=n; i++) {
		d2.insert({get<1>(v[i]), get<3>(v[i])});
		while(i+1<=n&&get<0>(v[i+1])==get<0>(v[i])) {
			int id=get<3>(v[i+1]);
			d2.insert({p[id][1], id});
			i++;
		}
		process();
	}
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]))){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
memset(vis,0,sizeof(vis));
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==0){ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;int ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((int)ans,(int)sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;double ans=100000.0;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((double)ans,(double)sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((ll)ans,(ll)(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 ll int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 ll int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000007;int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}

   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
memset(vis,0,sizeof(vis));
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
   cout<<i+1<<" "<<j+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0; vis[i]=1;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((ll)ans,(ll)(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    if(cc==0)continue;
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;long double ans=1000000000.0;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;

int ff=0;
for(int jj=0;jj<n;jj++){
if(vis[jj]==1||jj==i||jj==j)continue;
if((a[jj]>=min(a[i],a[j])&&a[jj]<=max(a[i],a[j]))||(b[jj]>=min(b[i],b[j])&&b[jj]<=max(b[i],b[j]))){ff=1;break;}}
    if(ff==0){
        ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;break;}
        }

//cout<<fixed<<setprecision(3)<<ans<<"\n";
//if(ans<10000000.0){//cout<<ans<<" ";
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;}
 //}
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000000000000000;
        if(vis[i]==0){
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}}
    if(cc==0)continue;
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;

 }
 //for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 //}
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;double ans=100000.0;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
        ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
        }
else if(ans==sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
if(abs(c[cc]-c[i])>abs(c[j]-c[i])){
ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
}
}
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
memset(vis,0,sizeof(vis));
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;
        if(vis[i]==0){ll ans=1000000000; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}

   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0; vis[i]=1;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;long double ans=1000000000.0;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
        ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
        }
else if(ans==sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
if(abs(c[cc]-c[i])>abs(c[j]-c[i])){
ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
}
}
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    if(cc==0)continue;
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;long double ans=10000000.0;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
        ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
        }
else if(ans==sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0){
if(abs(c[cc]-c[i])>abs(c[j]-c[i])){
ans=min((double)ans,(double)(sqrt(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))*1.0));
        cc=j;
}
}
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}

   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 ll int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  ll int a[n];ll b[n]; ll c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}}
    if(cc==0)continue;
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;

 }
 //for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 //}
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
memset(vis,0,sizeof(vis));
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
  int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};vis[0]=0;
 //ll int ans=INT_MAX;
 vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
memset(vis,0,sizeof(vis));
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){
        if(vis[i]==0){ll ans=1000000000;ll int cc=0; vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}
    }
   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j&&vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((ll)ans,(ll)(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
ll int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]))){
        ans=#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 int n;
 cin>>n;
 int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((ll)ans,(ll)(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
 cin>>n;
  int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
 int vis[n];
for(int i=0;i<n;i++)vis[i]=0;
 //ll int ans=INT_MAX;
// vector<pair<ll int,ll int>>v;
 for(ll int i=0;i<n;i++){ll int cc=0;ll ans=1000000009;
        if(vis[i]==0){ vis[i]=1;
    for(ll int j=0;j<n;j++){
        if(i!=j&&vis[j]==0){
  ll int etc=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        if(ans>etc){
        ans=((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
        cc=j;
        }
}
}

   cout<<i+1<<" "<<cc+1<<"\n";
  vis[i]=1;
    vis[cc]=1;
}
 }
 for(int i=0;i<n/2;i++){
  //  cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
#define ll long long
using namespace std;
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}

int main(){
 ll int n;
 cin>>n;
 ll int a[n],b[n],c[n];
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
 }
ll int vis[n]={0};
 int ans=INT_MAX;
 vector<pair<int,int>>v;
 for(int i=0;i<n;i++){
        if(vis[i]==1)continue;ll ans=INT_MAX;int cc=0;
    for(int j=0;j<n;j++){
        if(i==j||vis[j]==1)continue;
        if(ans>(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j]))){
        ans=min((ll)ans,(ll)(abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])+abs(c[i]-c[j])*abs(c[i]-c[j])));
        cc=j;
        }
    }
    v.push_back(make_pair(i+1,cc+1));
  vis[i]=1;
    vis[cc]=1;
 }
 for(int i=0;i<n/2;i++){
    cout<<v[i].f<<" "<<v[i].s<<"\n";
 }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur].size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<n && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur].size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<j<<" "<<mp[cur].size()<<endl;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      vector<pair<pair<pair<ll,ll>,ll>,ll>>v;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.pb(make_pair(make_pair(make_pair(a,b),c),i));

      }

      sort(v.begin(),v.end());
      vector<pair<pair<pair<ll,ll>,ll>,ll>>v1;

      for(int i = 0;i<n;i+=2)
      {
          ll cur = v[i].first.first.first;
          //cout<<v[i].first.first.first<<" "<<v[i].first.first.second<<" "<<v[i].first.second<<endl;
          //cout<<v[i+1].first.first.first<<" "<<v[i+1].first.first.second<<" "<<v[i+1].first.second<<endl;

           if(i+1<n && v[i+1].first.first.first == v[i].first.first.first)
          cout<<v[i].second+1<<" "<<v[i+1].second+1<<endl;
          else
          {
              v1.pb(v[i]);
              i-=1;
          }

      }
        sort(v1.begin(),v1.end());

      for(int i = 0;i<v1.size();i+=2)
      {
          //cout<<v1[i].first.first.first<<" "<<v1[i].first.first.second<<" "<<v1[i].first.second<<endl;
          //cout<<v1[i+1].first.first.first<<" "<<v1[i+1].first.first.second<<" "<<v1[i+1].first.second<<endl;
          cout<<v1[i].second+1<<" "<<v1[i+1].second+1<<endl;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          v.insert(b);
          v.insert(c);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur].size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<j<<" "<<mp[cur].size()<<endl;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }

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

       vector<pair<ll,pair<ll,ll>>>ans1;

      rep(j,0,ans.size())
      {
          if(j+1<ans.size() && ans[j].first==ans[j+1].first)
          {
              cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
              j++;
          }
          else
          {
              ans1.pb(ans[j]);
          }
      }

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

      rep(j,0,ans1.size())
      {
          cout<<mp1[make_pair(ans1[j].first,make_pair(ans1[j].second.first,ans1[j].second.second))]+1<<" "<<mp1[make_pair(ans1[j+1].first,make_pair(ans1[j+1].second.first,ans1[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur[.size()] && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          v.insert(b);
          v.insert(c);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur].size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<j<<" "<<mp[cur].size()<<endl;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }
      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<mp[cur].size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

struct l{

    ll a1,b1,c1,d1;
};

int main()
{

      ll n;
      cin>>n;

      vector<pair<pair<pair<ll,ll>,ll>,ll>>v;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.pb(make_pair(make_pair(make_pair(a,b),c),i));

      }

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

      for(int i = 0;i<n;i+=2)
      {
          cout<<v[i].second+1<<" "<<v[i+1].second+1<<endl;
      }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{

      ll n;
      cin>>n;

      map<ll,vector<pair<ll,ll>>>mp;
      set<ll>v;
      map<pair<ll,pair<ll,ll>>,ll>mp1;

      rep(i,0,n)
      {
          ll a,b,c;
          cin>>a>>b>>c;

          v.insert(a);
          mp[a].pb(make_pair(b,c));
          mp1[make_pair(a,make_pair(b,c))] = i;
      }

      vector<pair<ll,pair<ll,ll>>>ans;

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

      for(auto cur:v)
      {
          //ll cur = v[i];

          sort(mp[cur].begin(),mp[cur].end());

          for(int j = 0;j<mp[cur].size();j+=2)
          {
              //cout<<cur<<" "<<mp[cur][j].first<<" "<<mp[cur][j].second<<endl;
              if(j+1<v.size() && mp[cur][j+1].first==mp[cur][j].first)
              {
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1;
                  //cout<<mp1[make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second))]+1<<" "<<mp1[make_pair(cur,make_pair(mp[cur][j+1].first,mp[cur][j+1].second))]+1<<endl;
              }
              else
              {
                  ans.pb(make_pair(cur,make_pair(mp[cur][j].first,mp[cur][j].second)));
                  j-=1;
              }
          }
      }      sort(ans.begin(),ans.end());

      rep(j,0,ans.size())
      {
          cout<<mp1[make_pair(ans[j].first,make_pair(ans[j].second.first,ans[j].second.second))]+1<<" "<<mp1[make_pair(ans[j+1].first,make_pair(ans[j+1].second.first,ans[j+1].second.second))]+1<<endl;
          j++;
      }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

ll mp[10000];

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld%lld%lld",&x,&y,&z);
        str st= {x,y,z};
        v.push_back(st);
    }

    i=-1;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;

            }

            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                printf("%lld %lld\n",i+1,j+1);
                i=-1;
                c++;
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }
    map<ll,ll>mp;
    i=0;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp.count(i)==1)
            continue;
        for(j=0; j<n; j++)
        {
            if(j==i)continue;
            if(c==(n/2))
                break;
            if(mp.count(j)==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp.count(k)==1)continue;
                    continue;
                if(k==i || k==j)
                    continue;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;
                //cout << k+1 << " " << ret << " ===\n";
            }

            //cout << i+1 << " " << j+1 << " " << flag << " ++\n";
            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                i=-1;
                c++;
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

ll mp[10000];

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld%lld%lld",&x,&y,&z);
        str st= {x,y,z};
        v.push_back(st);
    }

    i=-1;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;
                if(flag==1)break;

            }

            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                printf("%lld %lld\n",i+1,j+1);
                c++;
                break;
            }
        }
        if(i==(n-1))i=-1;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

ll mp[10000];

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld%lld%lld",&x,&y,&z);
        str st= {x,y,z};
        v.push_back(st);
    }

    i=-1;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;

            }

            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                printf("%lld %lld\n",i+1,j+1);
                c++;
                break;
            }
        }
        if(i==(n-1))i=-1;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

ll mp[10000];

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }

    i=-1;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;

            }

            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                i=-1;
                c++;
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }
    map<ll,ll>mp;
    i=0;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;
                //cout << k+1 << " " << ret << " ===\n";
            }

            //cout << i+1 << " " << j+1 << " " << flag << " ++\n";
            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                i=-1;
                c++;
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
        return 0;
    if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        return 0;
    if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
        return 0;
    return 1;
}

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }
    map<ll,ll>mp;
    for(i=0; i<n; i++)
    {
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==1)
                    flag=1;
            }
            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }
    map<ll,ll>mp;
    i=-1;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;
                //cout << k+1 << " " << ret << " ===\n";
            }

            //cout << i+1 << " " << j+1 << " " << flag << " ++\n";
            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                i=-1;
                c++;
                break;
            }

        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

struct str
{
    ll x,y,z;
};

bool cmp(str a,str b,str c)
{
    if(min(a.x,b.x)<=c.x && max(a.x,b.x)>=c.x)
    {
        if(min(a.y,b.y)<=c.y && max(a.y,b.y)>=c.y)
        {
            if(min(a.z,b.z)<=c.z && max(a.z,b.z)>=c.z)
                return 0;
        }
    }

    return 1;
}

int main()
{
    ll n,i,a,x,y,z,c=0,k,j,flag;
    vector<str>v;

    cin >> n;
    for(i=0; i<n; i++)
    {
        cin >> x >> y >> z;
        str st= {x,y,z};
        v.push_back(st);
    }
    map<ll,ll>mp;
    i=0;
    while(i<n)
    {
        i++;
        if(c==(n/2))
            break;
        if(mp[i]==1)
            continue;
        for(j=i+1; j<n; j++)
        {
            if(c==(n/2))
                break;
            if(mp[j]==1)
                continue;
            flag=0;
            for(k=0; k<n; k++)
            {
                if(mp[k]==1)
                    continue;
                if(k==i || k==j)
                    continue;
                if(c==(n/2))
                    break;
                ll ret=cmp(v[i],v[j],v[k]);
                if(ret==0)
                    flag=1;
            }

            if(flag==0)
            {
                mp[i]=1;
                mp[j]=1;
                cout << i+1 << " " << j+1 << "\n";
                i=-1;
                break;
            }

        }
    }

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    int n ; cin >> n ;
    vector <vector <int>> v ;
    int a, b, c;
    map< vector <int> , int> m;
    for (int i = 0; i < n; i++){
        cin >>a >> b >> c;
        vector <int >v1;
        v1.push_back(a);
        v1.push_back(b);
        v1.push_back(c);
        m[v1] = i+1;
        v.push_back(v1);
        //cout << 1;
    }
    sort (v.begin() , v.end());
    for (int i = 0; i <n ;i+=2){
        vector <int> v1 = v[i];
        vector <int> v2 = v[i+1];
        cout <<m[v[i]]<< " "<< m[v[i+1]]<< endl;
    }

}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    int n ; cin >> n ;
    vector <vector <int>> v ;
    int a, b, c;
    map< vector <int> , int> m;
    for (int i = 0; i < n; i++){
        cin >>a >> b >> c;
        vector <int >v1;
        v1.push_back(a);
        v1.push_back(b);
        v1.push_back(c);
        m[v1] = i+1;
        v.push_back(v1);
        //cout << 1;
    }
    sort (v.begin() , v.end());
    n = n/2;
    for (int i = 1 ; i <=n; i++){
        vector <int> v1 = v[i];
        vector <int> v2 = v[i+1];
        cout <<m[v[n-i]]<< " "<< m[v[n+i-1]]<< endl;
    }

}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    int n ; cin >> n ;
    vector <vector <int>> v ;
    int a, b, c;
    map< vector <int> , int> m;
    for (int i = 0; i < n; i++){
        cin >>a >> b >> c;
        vector <int >v1;
        v1.push_back(a);
        v1.push_back(b);
        v1.push_back(c);
        m[v1] = i+1;
        v.push_back(v1);
        //cout << 1;
    }
    sort (v.begin() , v.end());
    //int j = i;
    vector <vector<int>>v2;
    for (int i=0; i <n; i++){
       if(i==n-1){v2.push_back(v[i]);continue;}
       if (v[i][0] == v[i+1][0]){
           if (v[i][1]==v[i+1][1]){
               cout<< m[v[i]]<< " "<< m[v[i+1]]<< endl;i++; continue;
           }
       }
       v2.push_back(v[i]);
    }

    vector <vector<int>>v3;
    for ( int i=0; i <v2.size(); i++){
        if(i==v2.size()-1){v3.push_back(v2[i]);continue;}
       if (v2[i][0] == v2[i+1][0]){
               cout<< m[v2[i]]<< " "<< m[v2[i+1]]<< endl;i++; continue;
           }
       v3.push_back(v2[i]);
    }
     for (int i=0; i <v3.size()-1; i+=2){
               cout<< m[v3[i]]<< " "<< m[v3[i+1]]<< endl; continue;
       }

}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    int n ; cin >> n ;
    vector <vector <int>> v ;
    int a, b, c;
    map< vector <int> , int> m;
    for (int i = 0; i < n; i++){
        cin >>a >> b >> c;
        vector <int >v1;
        v1.push_back(a);
        v1.push_back(b);
        v1.push_back(c);
        m[v1] = i+1;
        v.push_back(v1);
        //cout << 1;
    }
    sort (v.begin() , v.end());
    //int j = i;
    vector <vector<int>>v2;
    for (int i=0; i <n; i++){
        if(i==n-1){v2.push_back(v[i]);continue;}
       if (v[i][0] == v[i+1][0]){
           if (v[i][1]==v[i+1][1]){
               cout<< m[v[i]]<< " "<< m[v[i+1]]<< endl;i++; continue;
           }
       }
       v2.push_back(v[i]);
       //cout << m[v[i]]<< endl;
    }
    vector <vector<int>>v3;
    for ( int i=0; i <v2.size(); i++){
        if(i==v2.size()-1){v3.push_back(v2[i]);continue;}
       if (v2[i][0] == v2[i+1][0]){
               cout<< m[v2[i]]<< " "<< m[v2[i+1]]<< endl;i++; continue;
           }
       v3.push_back(v2[i]);
    }
     for (int i=0; i <v3.size()-1; i++){
               cout<< m[v3[i]]<< " "<< m[v3[i+1]]<< endl;i++; continue;
       }

}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
    int n ; cin >> n ;
    vector <vector <int>> v ;
    int a, b, c;
    map< vector <int> , int> m;
    for (int i = 0; i < n; i++){
        cin >>a >> b >> c;
        vector <int >v1;
        v1.push_back(a);
        v1.push_back(b);
        v1.push_back(c);
        m[v1] = i+1;
        v.push_back(v1);
        //cout << 1;
    }
    sort (v.begin() , v.end());
    //int j = i;
    vector <vector<int>>v2;
    for (int i=0; i <n; i++){
       if(i==n-1){v2.push_back(v[i]);continue;}
       if (v[i][0] == v[i+1][0]){
           if (v[i][1]==v[i+1][1]){
               cout<< m[v[i]]<< " "<< m[v[i+1]]<< endl;i++; continue;
           }
       }
       v2.push_back(v[i]);
    }

    vector <vector<int>>v3;
    for ( int i=0; i <v2.size(); i++){
        if(i==v2.size()-1){v3.push_back(v2[i]);continue;}
       if (v2[i][0] == v2[i+1][0]){
               cout<< m[v2[i]]<< " "<< m[v2[i+1]]<< endl;i++; continue;
           }
       v3.push_back(v2[i]);
    }
     for (int i=0; i+1 <v3.size(); i+=2){
               cout<< m[v3[i]]<< " "<< m[v3[i+1]]<< endl; continue;
       }

}