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 RLEN = 1 << 18 | 1;
inline char nc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? -1 : *ib++;
}
inline int rd() {
  char ch = nc();
  int i = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (isdigit(ch)) {
    i = (i << 1) + (i << 3) + ch - '0';
    ch = nc();
  }
  return i * f;
}
const int N = 1e3 + 50;
int n, m, vis[N];
struct P {
  int x, y, col, id;
  P(int x = 0, int y = 0, int col = 0, int id = 0)
      : x(x), y(y), col(col), id(id) {}
  friend inline P operator-(const P &a, const P &b) {
    return P(a.x - b.x, a.y - b.y);
  }
  friend inline int operator*(const P &a, const P &b) {
    return a.x * b.y - a.y * b.x;
  }
} p[N], q[N];
vector<pair<int, int> > ans;
inline void add(int x, int y) { ans.push_back(pair<int, int>(x, y)); }
inline bool in(P a, P b, P c, P d) {
  return (a - d) * (b - d) > 0 && (b - d) * (c - d) > 0 &&
         (c - d) * (a - d) > 0;
}
inline void solve(P a, P b, P c) {
  for (int i = 1; i <= n; i++)
    if (in(a, b, c, p[i]) && p[i].col != a.col) {
      add(p[i].id, c.id);
      solve(c, p[i], b);
      solve(a, b, p[i]);
      solve(p[i], c, a);
      return;
    }
  vector<P> vec;
  for (int i = 1; i <= n; i++)
    if (in(a, b, c, p[i])) add(a.id, p[i].id);
}
int main() {
  n = rd();
  for (int i = 1; i <= n; i++)
    p[i].x = rd(), p[i].y = rd(), p[i].col = rd(), p[i].id = i;
  if (n == 2) {
    if (p[1].col ^ p[2].col)
      puts("1\n1 2");
    else
      puts("0");
    return 0;
  }
  sort(p + 1, p + n + 1, [&](const P &a, const P &b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
  });
  sort(p + 2, p + n + 1,
       [&](const P &a, const P &b) { return (a - p[1]) * (b - p[1]) > 0; });
  q[m = 1] = p[1];
  for (int i = 2; i <= n; i++) {
    while (m >= 2 && (p[i] - q[m - 1]) * (q[m] - q[m - 1]) > 0) --m;
    q[++m] = p[i];
  }
  int fir[2] = {0, 0}, lst[2] = {0, 0}, cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (q[i].col != q[i % m + 1].col) {
      ++cnt;
      if (cnt > 2) {
        puts("Impossible");
        return 0;
      }
      if (!fir[0]) {
        fir[0] = i, fir[1] = i % m + 1;
        if (q[i].col != q[(i == 1) ? m : (i - 1)].col)
          lst[1] = i, lst[0] = i % m + 1;
      } else
        lst[1] = i, lst[0] = i % m + 1;
    }
  }
  for (int i = 1; i <= m; i++) vis[q[i].id] = 1;
  if (!cnt) {
    int tag = 0;
    for (int i = 1; i <= n; i++)
      if (!vis[i] && p[i].col != q[1].col) {
        for (int j = 1; j <= m; j++) {
          if (j != m) add(q[j].id, q[j + 1].id);
          solve(q[j], q[j % m + 1], p[i]);
        }
        tag = 1;
        break;
      }
    if (!tag)
      for (int i = 1; i < n; i++) add(p[i].id, p[n].id);
  } else {
    for (int i = fir[1]; i != lst[1]; i = i % m + 1) {
      add(q[i].id, q[i % m + 1].id);
      solve(q[i], q[i % m + 1], q[lst[0]]);
    }
    for (int i = lst[0]; i != fir[0]; i = i % m + 1) {
      add(q[i].id, q[i % m + 1].id);
      solve(q[i], q[i % m + 1], q[fir[1]]);
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first - 1 << ' ' << ans[i].second - 1 << '\n';
}