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;
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const int NINF = 0x3f3f3f40;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0x3f3f3f3f3f3f3f40;
const int mxN = 2001;
int n;
vector<pair<int, int> > ans;
void upd(int a, int b) { ans.push_back({a, b}); }
struct pt {
  ll x, y;
  pt(ll x = 0, ll y = 0) : x(x), y(y) {}
  bool operator<(const pt &o) const { return (x == o.x ? y < o.y : x < o.x); }
  pt operator-(const pt &o) const { return pt(x - o.x, y - o.y); }
} arr[mxN];
ll cross(pt a, pt b) { return a.x * b.y - a.y * b.x; }
ll area(pt a, pt b, pt c) { return abs(cross(b - a, c - a)); }
bool contains(pt a, pt b, pt c, pt check) {
  return area(a, b, check) + area(b, c, check) + area(c, a, check) ==
         area(a, b, c);
}
bool col[mxN];
int rk[mxN], stk[mxN], top;
bool cmp(int a, int b) {
  return cross(arr[a] - arr[rk[0]], arr[b] - arr[rk[0]]) > 0;
}
vector<int> chull() {
  for (int i = (0); i < (n); ++i) rk[i] = i;
  swap(rk[0], rk[min_element(arr, arr + n) - arr]);
  sort(rk + 1, rk + n, cmp);
  for (int i = (0); i < (n); ++i) {
    while (top > 1 && cross(arr[rk[i]] - arr[stk[top - 1]],
                            arr[stk[top - 1]] - arr[stk[top - 2]]) > 0)
      --top;
    stk[top++] = rk[i];
  }
  return vector<int>(stk, stk + top);
}
void solve(int a, int b, int c, vector<int> req) {
  for (int k : req) {
    if (col[k] == col[a]) {
      upd(a, k);
      vector<int> nxt1, nxt2, nxt3;
      for (int p : req) {
        if (p ^ k) {
          if (contains(arr[c], arr[a], arr[k], arr[p]))
            nxt1.push_back(p);
          else if (contains(arr[b], arr[a], arr[k], arr[p]))
            nxt2.push_back(p);
          else
            nxt3.push_back(p);
        }
      }
      solve(c, a, k, nxt1);
      solve(b, a, k, nxt2);
      solve(k, b, c, nxt3);
      return;
    }
  }
  for (int k : req) {
    upd(b, k);
  }
}
int main() {
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  int a, b, c;
  for (int i = (0); i < (n); ++i) {
    cin >> a >> b >> c;
    arr[i] = pt(a, b);
    col[i] = c;
  }
  vector<int> hull = chull();
  for (int i = (1); i < (hull.size()); ++i) {
    if (col[hull[i - 1]] != col[hull[i]]) {
      hull.insert(hull.end(), hull.begin(), hull.begin() + i);
      hull.erase(hull.begin(), hull.begin() + i);
      break;
    }
  }
  int difcol = 0;
  for (int i = (1); i < (hull.size()); ++i) {
    if (col[hull[i - 1]] != col[hull[i]]) difcol++;
  }
  if (difcol > 1) {
    cout << "Impossible\n";
    exit(0);
  }
  if (difcol == 0) {
    for (int i = (1); i < (hull.size()); ++i) {
      upd(hull[i - 1], hull[i]);
    }
    bool flag = false;
    for (int i = (0); i < (n); ++i) {
      if (col[i] != col[hull[0]]) {
        vector<int> req;
        for (int j = (0); j < (hull.size()); ++j) {
          for (int k = (0); k < (n); ++k) {
            if (k != i && k != hull[j] && k != hull[(j + 1) % hull.size()] &&
                contains(arr[i], arr[hull[j]], arr[hull[(j + 1) % hull.size()]],
                         arr[k]))
              req.push_back(k);
          }
          solve(i, hull[j], hull[(j + 1) % hull.size()], req);
          req.clear();
        }
        flag = true;
        break;
      }
    }
    if (!flag) {
      for (int i = (0); i < (n); ++i) {
        for (int k : hull) {
          if (k == i) goto nxt;
        }
        upd(i, hull[0]);
      nxt:;
      }
    }
  } else {
    int bp;
    for (int i = (1); i < (hull.size()); ++i) {
      if (col[hull[i - 1]] != col[hull[i]]) bp = i;
    }
    vector<int> req;
    for (int j = (1); j < (bp); ++j) {
      upd(hull[j - 1], hull[j]);
      for (int k = (0); k < (n); ++k) {
        if (k != hull[bp] && k != hull[j - 1] && k != hull[j] &&
            contains(arr[hull[bp]], arr[hull[j]], arr[hull[j - 1]], arr[k]))
          req.push_back(k);
      }
      solve(hull[bp], hull[j], hull[j - 1], req);
      req.clear();
    }
    for (int j = (bp + 1); j < (hull.size()); ++j) {
      upd(hull[j - 1], hull[j]);
      for (int k = (0); k < (n); ++k) {
        if (k != hull[0] && k != hull[j - 1] && k != hull[j] &&
            contains(arr[hull[0]], arr[hull[j]], arr[hull[j - 1]], arr[k]))
          req.push_back(k);
      }
      solve(hull[0], hull[j], hull[j - 1], req);
      req.clear();
    }
  }
  cout << ans.size() << "\n";
  for (auto p : ans) {
    cout << (p.first) << " " << (p.second) << "\n";
  }
  return 0;
}