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;
int n, stk[1010], tp, ord[1010];
struct Vector {
  int x, y;
  Vector(int X = 0, int Y = 0) { x = X, y = Y; }
  friend Vector operator+(const Vector &u, const Vector &v) {
    return Vector(u.x + v.x, u.y + v.y);
  }
  friend Vector operator-(const Vector &u, const Vector &v) {
    return Vector(u.x - v.x, u.y - v.y);
  }
  friend int operator&(const Vector &u, const Vector &v) {
    return u.x * v.y - u.y * v.x;
  }
  friend int operator|(const Vector &u, const Vector &v) {
    return u.x * v.x + u.y * v.y;
  }
  double operator~() const { return atan2(y, x); }
  void read() { scanf("%d%d", &x, &y); }
  void print() { printf("(%d,%d)", x, y); }
} p[1010];
bool col[1010];
vector<pair<int, int> > edges;
void solve(int u, int v, int w) {
  bool minor = col[u] ^ col[v] ^ col[w];
  int MINOR;
  if (col[u] == minor) MINOR = u;
  if (col[v] == minor) MINOR = v;
  if (col[w] == minor) MINOR = w;
  for (int i = 0; i < n; i++) {
    if (i == u || i == v || i == w) continue;
    if (col[i] != minor) continue;
    bool U = ((p[u] - p[i]) & (p[v] - p[i])) > 0;
    bool V = ((p[v] - p[i]) & (p[w] - p[i])) > 0;
    bool W = ((p[w] - p[i]) & (p[u] - p[i])) > 0;
    if (U != V || V != W || W != U) continue;
    edges.push_back(make_pair(MINOR, i));
    solve(u, v, i), solve(v, w, i), solve(w, u, i);
    return;
  }
  for (int i = 0; i < n; i++) {
    if (i == u || i == v || i == w) continue;
    bool U = ((p[u] - p[i]) & (p[v] - p[i])) > 0;
    bool V = ((p[v] - p[i]) & (p[w] - p[i])) > 0;
    bool W = ((p[w] - p[i]) & (p[u] - p[i])) > 0;
    if (U != V || V != W || W != U) continue;
    if (col[u] == col[i]) {
      edges.push_back(make_pair(u, i));
      continue;
    }
    if (col[v] == col[i]) {
      edges.push_back(make_pair(v, i));
      continue;
    }
    if (col[w] == col[i]) {
      edges.push_back(make_pair(w, i));
      continue;
    }
  }
}
bool onhull[1010];
void print() {
  printf("%d\n", edges.size());
  for (auto i : edges) printf("%d %d\n", i.first, i.second);
  exit(0);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) p[i].read(), scanf("%d", &col[i]), ord[i] = i;
  sort(ord, ord + n, [](int u, int v) {
    return p[u].x == p[v].x ? p[u].y < p[v].y : p[u].x < p[v].x;
  });
  for (int i = 1; i < n; i++) p[ord[i]] = p[ord[i]] - p[ord[0]];
  p[ord[0]] = Vector(0, 0);
  sort(ord + 1, ord + n, [](int u, int v) { return ~p[u] < ~p[v]; });
  stk[tp++] = ord[0];
  for (int i = 1; i < n; i++) {
    while (tp >= 2 && ((p[ord[i]] - p[stk[tp - 1]]) &
                       (p[stk[tp - 1]] - p[stk[tp - 2]])) >= 0)
      tp--;
    stk[tp++] = ord[i];
  }
  for (int i = 0; i < tp; i++) onhull[stk[i]] = true;
  int l = tp, r = 1;
  while (r < l && col[stk[r]] == col[stk[0]]) r++;
  while (l > r && col[stk[l - 1]] == col[stk[0]]) l--;
  if (r == l) {
    for (int j = 1; j < tp; j++) edges.push_back(make_pair(stk[j - 1], stk[j]));
    for (int i = 0; i < n; i++) {
      if (onhull[i] || col[i] == col[stk[0]]) continue;
      for (int j = 0; j < tp; j++) solve(stk[j], stk[(j + 1) % tp], i);
      print();
    }
    for (int i = 0; i < n; i++) {
      if (onhull[i]) continue;
      for (int j = i + 1; j < n; j++)
        if (!onhull[j]) edges.push_back(make_pair(i, j));
      if (col[i] == col[stk[0]]) edges.push_back(make_pair(i, stk[0]));
      print();
    }
  } else {
    for (int i = r; i < l; i++)
      if (col[stk[i]] == col[stk[0]]) {
        puts("Impossible");
        return 0;
      }
    for (int i = (l + 1) % tp; i != r; i = (i + 1) % tp)
      edges.push_back(make_pair(stk[(i + tp - 1) % tp], stk[i]));
    for (int i = r + 1; i < l; i++)
      edges.push_back(make_pair(stk[i - 1], stk[i]));
    for (int i = (l + 1) % tp; i != r; i = (i + 1) % tp)
      solve(stk[(i + tp - 1) % tp], stk[i], stk[r]);
    for (int i = r + 1; i < l; i++) solve(stk[i - 1], stk[i], stk[l % tp]);
    print();
  }
  print();
  return 0;
}