#include "bits/stdc++.h"
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
map<int, int> Puntaje;
vector< pair<int, int> > Pares(n);
for(int i = 0; i < n; i++){
cin>>Pares[i].first>>Pares[i].second;
Puntaje[(Pares[i].first + Pares[i].second) % (2 * n)]++;
}
int Mayor = -2, Valor = -2, Tiempo = n;
for(int i = 1; i < n * 2; i += 2){
if(Puntaje[i] > Mayor){
Mayor = Puntaje[i];
Valor = i;
Tiempo = n - Puntaje[i];
}
}
set< pair<int, int> > Pares_posibles;
for(int i = 0; i < n * 2; i++){
int A_adir = ((Valor - i) % (2 * n) + 2 * n) % 2 * n;
Pares_posibles.insert({i, Valor - i});
}
cout<<Tiempo<<"\n";
for(int i = 0; i < n; i++){
if(Pares_posibles.count(Pares[i]) == 1){
Pares_posibles.erase(Pares[i]);
swap(Pares[i].first, Pares[i].second);
Pares_posibles.erase(Pares[i]);
continue;
}
auto E = Pares_posibles.lower_bound({Pares[i].first, -2});
int Extremo = E->second;
cout<<i<<" "<<Pares[i].second<<" "<<Extremo<<"\n";
Pares_posibles.erase({Pares[i].first, Extremo});
Pares_posibles.erase({Extremo, Pares[i].first});
}
return 0;
}