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;
int x[1024], y[1024], c[1024];
int pts[1024];
int chull[1024], tp;
int chull_size;
int ans_l[1024], ans_r[1024], ans_len = 0;
void add_edge(int u, int v) {
  ans_l[ans_len] = u;
  ans_r[ans_len] = v;
  ans_len++;
}
void print_ans() {
  printf("%d\n", ans_len);
  for (int i = 0; i < ans_len; i++) printf("%d %d\n", ans_l[i], ans_r[i]);
}
bool ccw(int i, int j, int k) {
  return (x[i] * y[j] + x[j] * y[k] + x[k] * y[i] - x[j] * y[i] - x[k] * y[j] -
          x[i] * y[k]) > 0;
}
int pivot;
bool comp_by_pivot(int i, int j) {
  assert(i != pivot);
  assert(j != pivot);
  return ccw(pivot, i, j);
}
void run(int i, int j, int k, const vector<int> &inner, bool sep) {
  if (inner.size() == 0) {
    if (sep) {
      ;
    } else {
      add_edge(j, k);
    }
  } else {
    int pivot = -1;
    for (int p : inner) {
      if (pivot == -1 || ccw(j, p, pivot)) pivot = p;
    }
    vector<int> j_inner, k_inner;
    for (int p : inner)
      if (p != pivot) {
        if (ccw(pivot, i, p))
          j_inner.push_back(p);
        else
          k_inner.push_back(p);
      }
    if (c[pivot] == c[i]) {
      run(j, pivot, i, j_inner, false);
      run(k, i, pivot, k_inner, true);
      if (!sep) add_edge(j, k);
    } else {
      run(i, j, pivot, j_inner, false);
      run(i, pivot, k, k_inner, sep);
    }
  }
}
void run(int i, int j, int k, bool sep) {
  assert(i != j && j != k && k != i);
  assert(ccw(i, j, k));
  vector<int> inner;
  for (int l = 0; l < n; l++)
    if (l != i && l != j && l != k && ccw(i, j, l) && ccw(j, k, l) &&
        ccw(k, i, l)) {
      inner.push_back(l);
    }
  run(i, j, k, inner, sep);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &x[i], &y[i], &c[i]);
  }
  if (n == 1) {
    printf("0\n");
  } else if (n == 2) {
    if (c[0] == c[1]) {
      printf("1\n");
      printf("0 1\n");
    } else {
      printf("0\n");
    }
  } else {
    pivot = 0;
    for (int i = 1; i < n; i++)
      if (x[i] < x[pivot] || (x[i] == x[pivot] && y[i] < y[pivot])) pivot = i;
    for (int i = 0; i < n - 1; i++) pts[i] = (i < pivot ? i : i + 1);
    sort(pts, pts + n - 1, comp_by_pivot);
    chull[0] = pivot;
    tp = 0;
    for (int i = 0; i < n - 1; i++) {
      int cur = pts[i];
      while (tp >= 1 && (ccw(chull[tp - 1], chull[tp], cur) == false)) tp--;
      chull[++tp] = cur;
    }
    chull_size = tp + 1;
    int num_change = 0;
    for (int i = 0; i < chull_size; i++)
      if (c[chull[i]] != c[chull[(i + 1) % chull_size]]) num_change++;
    if (num_change == 0) {
      int c_chull = c[chull[0]];
      int center_pivot = -1;
      for (int i = 0; i < n; i++)
        if (c[i] != c_chull) {
          center_pivot = i;
          break;
        }
      if (center_pivot == -1) {
        printf("%d\n", n - 1);
        for (int i = 0; i < n - 1; i++) printf("%d %d\n", pivot, pts[i]);
      } else {
        for (int i = 0; i < chull_size - 1; i++) {
          run(center_pivot, chull[i], chull[i + 1], false);
        }
        run(center_pivot, chull[chull_size - 1], chull[0], true);
        print_ans();
      }
    } else if (num_change == 2) {
      int p1 = -1;
      for (int i = 1; i < chull_size; i++)
        if (c[chull[i - 1]] != c[chull[i]]) {
          p1 = i;
          break;
        }
      assert(p1 >= 1 && p1 < chull_size);
      rotate(chull, chull + p1, chull + chull_size);
      int p2 = -1;
      for (int i = 1; i < chull_size; i++)
        if (c[chull[i - 1]] != c[chull[i]]) {
          p2 = i;
          break;
        }
      for (int i = 0; i < p2 - 1; i++) {
        run(chull[p2], chull[i], chull[i + 1], false);
      }
      for (int i = p2; i < chull_size - 1; i++) {
        run(chull[0], chull[i], chull[i + 1], false);
      }
      print_ans();
    } else {
      assert(num_change % 2 != 1);
      printf("Impossible\n");
    }
  }
  return 0;
}