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 Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct point {
  long long x, y;
  int c, id;
  point() {}
  point(long long x, long long y, int c = -1, int id = -1)
      : x(x), y(y), c(c), id(id) {}
  inline point operator-() const { return point(-x, -y); }
  inline point operator+(const point &pt) const {
    return point(x + pt.x, y + pt.y);
  }
  inline point operator-(const point &pt) const {
    return point(x - pt.x, y - pt.y);
  }
  inline point operator*(const long long &a) const {
    return point(x * a, y * a);
  }
  inline point operator/(const long long &a) const {
    return point(x / a, y / a);
  }
  inline long long operator*(const point &pt) const {
    return x * pt.y - y * pt.x;
  }
  inline bool operator<(const point &p) const {
    return make_pair(x, y) < make_pair(p.x, p.y);
  }
};
int n;
point ps[1005];
vector<int> get_hull() {
  vector<int> res;
  for (int i = 0; i < (n); ++i) {
    while (((int)(res).size()) > 1 &&
           (ps[i] - ps[res[((int)(res).size()) - 2]]) *
                   (ps[res.back()] - ps[res[((int)(res).size()) - 2]]) >=
               0) {
      res.pop_back();
    }
    res.push_back(i);
  }
  res.pop_back();
  vector<int> res2 = res;
  res.clear();
  for (int i = (n - 1); ((-1) > 0 ? i <= (0) : i >= (0)); i += (-1)) {
    while (((int)(res).size()) > 1 &&
           (ps[i] - ps[res[((int)(res).size()) - 2]]) *
                   (ps[res.back()] - ps[res[((int)(res).size()) - 2]]) >=
               0) {
      res.pop_back();
    }
    res.push_back(i);
  }
  res.pop_back();
  res2.insert(res2.end(), (res).begin(), (res).end());
  return res2;
}
bool inTriangle(int x, int a, int b, int c) {
  int jab = (ps[a] - ps[x]) * (ps[b] - ps[x]) > 0;
  int jbc = (ps[b] - ps[x]) * (ps[c] - ps[x]) > 0;
  int jca = (ps[c] - ps[x]) * (ps[a] - ps[x]) > 0;
  return jab == jbc && jbc == jca;
}
vector<pair<int, int> > egs;
void TriangleConnect(int a, int b, int c, vector<int> &pt) {
  int d = -1, ls = ps[a].c ^ ps[b].c ^ ps[c].c;
  for (int i = 0; i < (((int)(pt).size())); ++i) {
    if (ps[pt[i]].c == ls) {
      d = pt[i];
      break;
    }
  }
  if (!~d) {
    int co = ps[a].c == ls ? b : a;
    for (int i = 0; i < (((int)(pt).size())); ++i)
      egs.push_back(make_pair(co, pt[i]));
    return;
  }
  egs.push_back(make_pair(d, ps[a].c != ls ? (ps[b].c != ls ? c : b) : a));
  vector<int> pab, pbc, pca;
  for (int i = 0; i < (((int)(pt).size())); ++i) {
    if (pt[i] == d) continue;
    if (inTriangle(pt[i], a, b, d))
      pab.push_back(pt[i]);
    else if (inTriangle(pt[i], b, c, d))
      pbc.push_back(pt[i]);
    else
      pca.push_back(pt[i]);
  }
  TriangleConnect(a, b, d, pab);
  TriangleConnect(b, c, d, pbc);
  TriangleConnect(c, a, d, pca);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    scanf("%lld%lld%d", &ps[i].x, &ps[i].y, &ps[i].c);
    ps[i].id = i;
  }
  if (n == 1) return puts("0"), 0;
  sort(ps, ps + n);
  vector<int> h = get_hull();
  int se = 0;
  for (int i = 0; i < (((int)(h).size())); ++i)
    if (ps[h[i]].c != ps[h[(i + 1) % ((int)(h).size())]].c) ++se;
  if (se > 2) return puts("Impossible"), 0;
  if (!se) {
    int d = -1;
    for (int i = 0; i < (n); ++i)
      if (ps[i].c != ps[h[0]].c) {
        d = i;
        break;
      }
    if (!~d) {
      printf("%d\n", n - 1);
      for (int i = 1; i <= (n - 1); ++i) printf("%d %d\n", 0, i);
      return 0;
    }
    for (int i = 0; i < (((int)(h).size()) - 1); ++i)
      egs.push_back(make_pair(h[i], h[i + 1]));
    for (int i = 0; i < (((int)(h).size())); ++i) {
      int a = h[i], b = h[(i + 1) % ((int)(h).size())];
      vector<int> pts;
      for (int j = 0; j < (n); ++j)
        if (inTriangle(j, a, b, d)) pts.push_back(j);
      TriangleConnect(h[i], h[(i + 1) % ((int)(h).size())], d, pts);
    }
  } else {
    int f0 = -1, f1 = -1;
    for (int i = 0; i < (((int)(h).size())); ++i)
      if (ps[h[i]].c != ps[h[(i + 1) % ((int)(h).size())]].c) {
        if (ps[h[i]].c)
          f1 = i;
        else
          f0 = i;
      }
    for (int i = 0; i < (((int)(h).size())); ++i) {
      int a = h[i], b = h[(i + 1) % ((int)(h).size())], c;
      if (ps[a].c != ps[b].c) continue;
      egs.push_back(make_pair(a, b));
      if (ps[a].c)
        c = h[f0];
      else
        c = h[f1];
      vector<int> pts;
      for (int j = 0; j < (n); ++j)
        if (inTriangle(j, a, b, c)) pts.push_back(j);
      TriangleConnect(h[i], h[(i + 1) % ((int)(h).size())], c, pts);
    }
  }
  printf("%d\n", ((int)(egs).size()));
  for (int i = 0; i < (((int)(egs).size())); ++i)
    printf("%d %d\n", ps[egs[i].first].id, ps[egs[i].second].id);
  return 0;
}