Problem: On the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those civilizations and to explore the area they need to build roads between some of locations. But as always, there are some restrictions: 

  1. Every two locations of the same civilization are connected by a unique path of roads 
  2. No two locations from different civilizations may have road between them (explorers don't want to accidentally mix civilizations they are currently exploring) 
  3. Roads must be straight line segments
  4. Since intersections are expensive to build, they don't want any two roads to intersect (that is, only common point for any two roads may be at some of locations) 



Obviously all locations are different points in the plane, but explorers found out one more interesting information that may help you – no three locations lie on the same line!

Help explorers and find a solution for their problem, or report it is impossible.

Input

In the first line, integer n (1 ≤ n ≤ 10^3) - the number of locations discovered.

In next n lines, three integers x, y, c (0 ≤ x, y ≤ 10^4, c ∈ \{0, 1\}) - coordinates of the location and number of civilization it belongs to.

Output

In first line print number of roads that should be built.

In the following lines print all pairs of locations (their 0-based indices) that should be connected with a road.

If it is not possible to build roads such that all restrictions are met, print "Impossible". You should not print the quotation marks.

Example

Input

5
0 0 1
1 0 0
0 1 0
1 1 1
3 2 0


Output

3
1 4
4 2
3 0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
int n;
struct pt {
  int x, y, c, id;
  pt() {}
  pt(int x, int y, int c) : x(x), y(y), c(c) {}
  void in(int i) {
    cin >> x >> y >> c;
    id = i;
  }
  bool operator<(const pt &p) const {
    return make_pair(x, y) < make_pair(p.x, p.y);
  }
  bool operator==(const pt &p) const { return id == p.id; }
} P[N];
int vect(pt p, pt p1, pt p2) {
  return (p1.x - p.x) * (p2.y - p.y) - (p1.y - p.y) * (p2.x - p.x);
}
vector<pt> convex(vector<pt> &vec) {
  if (vec.size() <= 1) return vec;
  int n = vec.size(), k = 0;
  vector<pt> ch(2 * n);
  for (int i = 0; i < n; ch[k++] = vec[i++])
    while (k >= 2 && vect(ch[k - 2], ch[k - 1], vec[i]) <= 0) k--;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = vec[i--])
    while (k >= t && vect(ch[k - 2], ch[k - 1], vec[i]) <= 0) k--;
  ch.resize(k - 1);
  return ch;
}
vector<pair<int, int>> ans;
int sgn(int x) { return (x > 0) - (x < 0); }
bool isin(pt p, pt p1, pt p2, pt p3) {
  int sg1 = sgn(vect(p, p1, p2));
  int sg2 = sgn(vect(p, p2, p3));
  int sg3 = sgn(vect(p, p3, p1));
  return sg1 * sg2 == 1 && sg1 * sg3 == 1;
}
void insert(int x, int y) {
  if (x > y) swap(x, y);
  ans.emplace_back(x, y);
}
void solve(pt p, pt p1, pt p2) {
  vector<pt> in;
  for (int i = 1; i <= n; i++) {
    if (!isin(P[i], p, p1, p2)) continue;
    if (P[i].c == p.c) {
      solve(p1, P[i], p);
      solve(p2, P[i], p);
      solve(P[i], p1, p2);
      insert(i, p.id);
      return;
    }
    in.push_back(P[i]);
  }
  sort(in.begin(), in.end(), [&](pt a, pt b) {
    int v1 = abs(vect(a, p1, p2)), v2 = abs(vect(b, p1, p2));
    if (v1 != v2) return v1 < v2;
    return a < b;
  });
  if (in.size()) insert(p1.id, in[0].id);
  for (int i = 1; i < in.size(); i++) {
    insert(in[i - 1].id, in[i].id);
  }
}
void print() {
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  cout << ans.size() << endl;
  for (auto t : ans) {
    cout << t.first - 1 << ' ' << t.second - 1 << endl;
  }
  exit(0);
}
int main() {
  cin >> n;
  vector<pt> all;
  for (int i = 1; i <= n; i++) P[i].in(i), all.push_back(P[i]);
  sort(all.begin(), all.end());
  auto ch = convex(all);
  int cnt = 0;
  for (int i = 0; i < ch.size(); i++) {
    pt p1 = ch[i], p2 = ch[(i + 1) % ch.size()];
    if (p1.c != p2.c) cnt++;
  }
  if (cnt > 2) return puts("Impossible"), 0;
  if (cnt == 0) {
    for (int i = 1; i <= n; i++) {
      int flg = 0;
      for (pt c : ch) {
        if (c == P[i]) {
          flg = 1;
          break;
        }
      }
      if (!flg && P[i].c != ch[0].c) {
        for (int j = 1; j < ch.size(); j++) {
          insert(ch[j - 1].id, ch[j].id);
        }
        for (int j = 0; j < ch.size(); j++) {
          pt p1 = ch[j], p2 = ch[(j + 1) % ch.size()];
          solve(P[i], p1, p2);
        }
        print();
      }
    }
    for (int i = 1; i < all.size(); i++) {
      insert(all[i - 1].id, all[i].id);
    }
    print();
  }
  pt A, B;
  for (int i = 0; i < ch.size(); i++) {
    pt p1 = ch[i], p2 = ch[(i + 1) % ch.size()];
    if (p1.c == p2.c) insert(p1.id, p2.id);
    if (p1.c == 0 && p2.c == 1) A = p1;
    if (p1.c == 1 && p2.c == 0) B = p1;
  }
  for (int i = 0; i < ch.size(); i++) {
    pt p1 = ch[i], p2 = ch[(i + 1) % ch.size()];
    if (p1.c != p2.c) continue;
    if (p1.c == 0)
      solve(B, p1, p2);
    else
      solve(A, p1, p2);
  }
  print();
}