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 maxn = 1e3 + 10;
struct point {
  int x, y, c, i;
  point() {}
  point(int x, int y, int c = 0, int i = 0) : x(x), y(y), c(c), i(i) {}
} pnt[maxn];
int det(const point &a, const point &b) { return a.x * b.y - a.y * b.x; }
bool operator==(const point &a, const point &b) {
  return a.x == b.x && a.y == b.y;
}
point operator-(const point &a, const point &b) {
  return point(a.x - b.x, a.y - b.y);
}
bool in_range(const point &o, const point &a, const point &b, const point &c) {
  return det(a - o, b - o) > 0 && det(b - o, c - o) > 0;
}
bool in_triangle(const point &p, const point &a, const point &b,
                 const point &c) {
  if (p == a || p == b || p == c) return 0;
  if (det(c - a, b - a) > 0) return in_triangle(p, a, c, b);
  return in_range(a, b, p, c) && in_range(b, c, p, a) && in_range(c, a, p, b);
}
bool all_same;
int n, m, diff, hull[maxn << 1];
vector<pair<int, int> > ans;
void solve(const vector<point> &all, const point &a, const point &b,
           const point &c) {
  if (!all.size()) return;
  for (const auto &t : all)
    if (t.c == c.c) {
      vector<point> x, y, z;
      for (const auto &s : all) {
        if (in_triangle(s, a, b, t)) x.push_back(s);
        if (in_triangle(s, b, c, t)) y.push_back(s);
        if (in_triangle(s, a, c, t)) z.push_back(s);
      }
      solve(x, a, b, t);
      solve(y, c, t, b);
      solve(z, c, t, a);
      ans.push_back(make_pair(t.i, c.i));
      return;
    }
  for (const auto &t : all) ans.push_back(make_pair(t.i, a.i));
  return;
}
int main() {
  scanf("%d", &n);
  all_same = 1;
  for (int i = 1; i <= n; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    pnt[i] = point(x, y, c, i - 1);
    all_same &= (c == pnt[1].c);
  }
  sort(pnt + 1, pnt + n + 1,
       [&](point a, point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; });
  if (all_same) {
    printf("%d\n", n - 1);
    for (int i = 1; i < n; ++i) printf("%d %d\n", pnt[i].i, pnt[i + 1].i);
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    while (m > 1 &&
           det(pnt[hull[m]] - pnt[hull[m - 1]], pnt[i] - pnt[hull[m - 1]]) > 0)
      --m;
    hull[++m] = i;
  }
  for (int rem = m, i = n - 1; i; --i) {
    while (m > rem &&
           det(pnt[hull[m]] - pnt[hull[m - 1]], pnt[i] - pnt[hull[m - 1]]) > 0)
      --m;
    hull[++m] = i;
  }
  --m;
  for (int i = 1; i <= m; ++i) hull[i + m] = hull[i];
  for (int i = 1; i <= m; ++i)
    if (pnt[hull[i]].c != pnt[hull[i + 1]].c) {
      for (int j = 1; j <= m; ++j) hull[j] = hull[j + i];
      break;
    }
  for (int i = 1; i <= m; ++i) {
    if (pnt[hull[i]].c != pnt[hull[i + 1]].c) ++diff;
    if (diff > 1) {
      puts("Impossible");
      return 0;
    }
  }
  if (!diff) {
    for (int pivot = 1; pivot <= n; ++pivot)
      if (pnt[pivot].c != pnt[hull[1]].c) {
        bool flag = 1;
        for (int i = 1; i <= m; ++i)
          if (hull[i] == pivot) {
            flag = 0;
            break;
          }
        if (flag) {
          for (int i = 1; i <= m; ++i) {
            point a = pnt[hull[i]], b = pnt[hull[i + 1]], c = pnt[pivot];
            vector<point> all;
            for (int j = 1; j <= n; ++j)
              if (in_triangle(pnt[j], a, b, c)) all.push_back(pnt[j]);
            solve(all, a, b, c);
            if (i < m) ans.push_back(make_pair(a.i, b.i));
          }
          break;
        }
      }
  } else {
    for (int pivot = 1; pivot <= m; ++pivot)
      if (pnt[hull[pivot]].c != pnt[hull[1]].c) {
        for (int i = 1; i < pivot - 1; ++i) {
          point a = pnt[hull[i]], b = pnt[hull[i + 1]], c = pnt[hull[pivot]];
          vector<point> all;
          for (int j = 1; j <= n; ++j)
            if (in_triangle(pnt[j], a, b, c)) all.push_back(pnt[j]);
          solve(all, a, b, c);
          ans.push_back(make_pair(a.i, b.i));
        }
        for (int i = pivot; i < m; ++i) {
          point a = pnt[hull[i]], b = pnt[hull[i + 1]], c = pnt[hull[1]];
          vector<point> all;
          for (int j = 1; j <= n; ++j)
            if (in_triangle(pnt[j], a, b, c)) all.push_back(pnt[j]);
          solve(all, a, b, c);
          ans.push_back(make_pair(a.i, b.i));
        }
        break;
      }
  }
  printf("%d\n", ans.size());
  for (auto t : ans) printf("%d %d\n", t.first, t.second);
  return 0;
}