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>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c h, n;
};
template <class c>
rge<c> range(c h, c n) {
  return rge<c>{h, n};
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
  template <class c>
  muu &operator<<(const c &) {
    return *this;
  }
};
const int MN = 1e3 + 44;
pair<int, int> coo[MN];
int col[MN];
int n;
int det(int a, int b, int c) {
  return (coo[a].first - coo[b].first) * (coo[a].second - coo[c].second) -
         (coo[a].second - coo[b].second) * (coo[a].first - coo[c].first);
}
bool inside(int a, int b, int c, int i) {
  return abs(det(a, b, i)) + abs(det(b, c, i)) + abs(det(c, a, i)) ==
         abs(det(a, b, c));
}
vector<pair<int, int> > ans;
void go(int a, int b, int c) {
  vector<int> points;
  for (int i = 0; i < n; ++i)
    if (i != a && i != b && i != c && inside(a, b, c, i)) points.push_back(i);
  muu() << __FUNCTION__ << "#" << 62 << ": "
        << "["
           "coo"
           "["
           "a"
           ": "
        << (a)
        << "] "
           ": "
        << coo[a]
        << "] "
           "["
           "coo"
           "["
           "b"
           ": "
        << (b)
        << "] "
           ": "
        << coo[b]
        << "] "
           "["
           "coo"
           "["
           "c"
           ": "
        << (c)
        << "] "
           ": "
        << coo[c]
        << "] "
           "["
           "points"
           ": "
        << (points) << "] ";
  int more = (col[a] + col[b] + col[c]) >= 2;
  int oth = col[a] != more ? a : (col[b] != more ? b : c);
  assert(col[oth] != more);
  for (int x : points) {
    if (col[x] != more) {
      muu() << __FUNCTION__ << "#" << 70 << ": "
            << "["
               "col"
               "["
               "x"
               ": "
            << (x)
            << "] "
               ": "
            << col[x]
            << "] "
               "["
               "col"
               "["
               "oth"
               ": "
            << (oth)
            << "] "
               ": "
            << col[oth]
            << "] "
               "["
               "more"
               ": "
            << (more) << "] ";
      ans.emplace_back(x, oth);
      go(a, b, x);
      go(b, c, x);
      go(c, a, x);
      return;
    }
  }
  int m = col[a] == more ? a : b;
  for (int x : points) {
    muu() << __FUNCTION__ << "#" << 81 << ": "
          << "["
             "col"
             "["
             "m"
             ": "
          << (m)
          << "] "
             ": "
          << col[m]
          << "] "
             "["
             "col"
             "["
             "x"
             ": "
          << (x)
          << "] "
             ": "
          << col[x] << "] ";
    ans.emplace_back(m, x);
  }
}
int main() {
  scanf("%d", &n);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; ++i)
    scanf("%d%d%d", &coo[i].first, &coo[i].second, col + i);
  vector<int> order;
  for (int i = 0; i < n; ++i) order.push_back(i);
  sort(order.begin(), order.end(),
       [](int i, int j) { return coo[i] < coo[j]; });
  vector<int> up, down;
  for (int i : order) {
    while (up.size() >= 2u && det(up.back(), up[up.size() - 2], i) >= 0)
      up.pop_back();
    while (down.size() >= 2u && det(down.back(), down[down.size() - 2], i) <= 0)
      down.pop_back();
    up.push_back(i);
    down.push_back(i);
  }
  reverse(down.begin(), down.end());
  up.pop_back();
  down.pop_back();
  vector<int> hull = up;
  for (int y : down) hull.push_back(y);
  muu() << __FUNCTION__ << "#" << 123 << ": "
        << "["
           "hull"
           ": "
        << (hull) << "] ";
  vector<int> last_one, last_zero;
  int H = hull.size();
  for (int i = 0; i < H; ++i) {
    int c1 = col[hull[i]];
    int c2 = col[hull[(i + 1) % H]];
    if (c1 == 0 && c2 == 1)
      last_zero.push_back(i);
    else if (c1 == 1 && c2 == 0)
      last_one.push_back(i);
  }
  muu() << __FUNCTION__ << "#" << 134 << ": "
        << "["
           "last_one"
           ": "
        << (last_one)
        << "] "
           "["
           "last_zero"
           ": "
        << (last_zero) << "] ";
  if (last_one.size() >= 2u) {
    printf("Impossible\n");
    return 0;
  }
  if (last_one.size() == 1) {
    for (int i = 0; i < H; ++i)
      if (col[hull[i]] == col[hull[(i + 1) % H]])
        go(hull[col[hull[i]] == 0 ? last_one[0] : last_zero[0]], hull[i],
           hull[(i + 1) % H]);
    for (int i = 0; i < H; ++i)
      if (col[hull[i]] == col[hull[(i + 1) % H]]) {
        muu() << __FUNCTION__ << "#" << 147 << ": "
              << "["
                 "hull"
                 "["
                 "i"
                 ": "
              << (i)
              << "] "
                 ": "
              << hull[i]
              << "] "
                 "["
                 "hull"
                 "["
                 "(i + 1) % H"
                 ": "
              << ((i + 1) % H)
              << "] "
                 ": "
              << hull[(i + 1) % H] << "] ";
        ans.emplace_back(hull[i], hull[(i + 1) % H]);
      }
  } else {
    int oth = -1;
    for (int i = 0; i < n; ++i)
      if (col[i] != col[hull[0]]) oth = i;
    if (oth == -1)
      for (int i = 1; i < n; ++i) ans.emplace_back(0, i);
    else {
      for (int i = 0; i < H; ++i) {
        muu() << __FUNCTION__ << "#" << 159 << ": "
              << "["
                 "oth"
                 ": "
              << (oth)
              << "] "
                 "["
                 "hull"
                 "["
                 "i"
                 ": "
              << (i)
              << "] "
                 ": "
              << hull[i]
              << "] "
                 "["
                 "hull"
                 "["
                 "(i + 1) % H"
                 ": "
              << ((i + 1) % H)
              << "] "
                 ": "
              << hull[(i + 1) % H] << "] ";
        go(hull[i], hull[(i + 1) % H], oth);
      }
      for (int i = 0; i < H - 1; ++i) {
        ans.emplace_back(hull[i], hull[i + 1]);
        muu() << __FUNCTION__ << "#" << 165 << ": "
              << "["
                 "ans"
                 ": "
              << (ans) << "] ";
      }
    }
  }
  printf("%d\n", (int)ans.size());
  for (auto x : ans) {
    printf("%d %d\n", x.first, x.second);
    assert(col[x.first] == col[x.second]);
  }
}