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>
const int N = 10005, M = 1000000;
std::pair<int, int> operator-(std::pair<int, int> a, std::pair<int, int> b) {
  return std::pair<int, int>(a.first - b.first, a.second - b.second);
}
long long operator*(std::pair<int, int> a, std::pair<int, int> b) {
  return (long long)a.first * b.second - (long long)a.second * b.first;
}
int n, lu;
std::mt19937 rnd(std::time(0) + (size_t) new char);
std::pair<int, int> p[N];
int col[N];
long long area(int a, int b, int c) {
  return std::abs((p[b] - p[a]) * (p[c] - p[a]));
}
bool in_triangle(int first, int a, int b, int c) {
  return area(first, a, b) + area(first, a, c) + area(first, b, c) ==
         area(a, b, c);
}
void split(const std::vector<int> &first, int a, int b, int c,
           std::vector<int> &ret) {
  ret.clear();
  for (int t : first)
    if (in_triangle(t, a, b, c)) ret.emplace_back(t);
}
std::set<std::pair<int, int>> s;
void link(int first, int second) {
  if (first > second) std::swap(first, second);
  s.emplace(first, second);
}
void solve(int a, int b, int c, const std::vector<int> &first, int color) {
  std::vector<int> A, B, C, tmp;
  int cnt = 0, id = -1;
  for (int t : first)
    if (col[t] != color) ++cnt;
  if (!cnt) {
    link(a, b);
    for (int t : first) link(a, t);
    return;
  }
  if (cnt == first.size()) {
    link(a, b);
    for (int t : first) link(c, t);
    return;
  }
  int base = rnd() % cnt;
  for (int t : first)
    if (color != col[t] && !base--)
      id = t;
    else
      tmp.emplace_back(t);
  split(tmp, a, b, id, A), solve(a, b, id, A, color);
  split(tmp, b, c, id, B), solve(id, c, b, B, !color);
  split(tmp, c, a, id, C), solve(id, c, a, C, !color);
}
int rk[N], stack[N], top;
bool cmp(int first, int second) {
  return (p[first] - p[rk[0]]) * (p[second] - p[rk[0]]) > 0;
}
std::vector<int> convex_hull() {
  for (int i = 0; i < n; ++i) rk[i] = i;
  std::swap(rk[0], rk[std::min_element(p, p + n) - p]);
  std::sort(rk + 1, rk + n, cmp);
  for (int i = 0; i < n; ++i) {
    while (top > 1 && (p[rk[i]] - p[stack[top - 1]]) *
                              (p[stack[top - 1]] - p[stack[top - 2]]) >
                          0)
      --top;
    stack[top++] = rk[i];
  }
  return std::vector<int>(stack, stack + top);
}
bool onside[N];
std::vector<int> nodes, all;
void deal(int u, int v, int w, int q) {
  split(all, u, v, w, nodes), solve(u, v, w, nodes, q);
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> p[i].first >> p[i].second >> col[i];
  std::vector<int> h = convex_hull();
  for (int i = 1; i < h.size(); ++i)
    if (col[h[i - 1]] != col[h[i]]) {
      h.insert(h.end(), h.begin(), h.begin() + i);
      h.erase(h.begin(), h.begin() + i);
      break;
    }
  int cnt = 0;
  for (int i = 1; i < h.size(); ++i) cnt += col[h[i - 1]] != col[h[i]];
  if (cnt > 1) return std::cout << "Impossible\n", 0;
  for (int i = 0; i < h.size(); ++i) onside[h[i]] = 1;
  for (int i = 0; i < n; ++i)
    if (!onside[i]) all.emplace_back(i);
  int c = col[h[0]], last_black = -1;
  std::vector<int> white;
  white.emplace_back(h[0]);
  for (int i = 1; i < h.size(); ++i) {
    if (col[h[i]] == c) {
      if (col[h[i - 1]] != c) deal(h[0], h[i], h[i - 1], c);
      white.emplace_back(h[i]);
    } else {
      last_black = h[i];
      for (int j = 0; j + 1 < white.size(); ++j)
        deal(white[j], white[j + 1], h[i], c);
      white.clear(), white.emplace_back(h[0]);
      if (col[h[i - 1]] != c) deal(h[i - 1], h[i], h[0], !c);
    }
  }
  if (last_black == -1) {
    int center = -1;
    for (int e : all)
      if (col[e] != c) {
        center = e;
        break;
      }
    if (center == -1) {
      for (int i = 0; i + 1 < h.size(); ++i) link(h[i], h[i + 1]);
      for (int e : all) link(h[0], e);
    } else {
      all.erase(std::find(all.begin(), all.end(), center));
      h.emplace_back(h[0]);
      for (int i = 0; i + 1 < h.size(); ++i) deal(h[i], h[i + 1], center, c);
      s.erase(std::minmax(h[0], h[1]));
    }
  } else {
    for (int i = 0; i + 1 < white.size(); ++i)
      deal(white[i], white[i + 1], last_black, c);
  }
  std::cout << s.size() << '\n';
  for (auto e : s) std::cout << e.first << ' ' << e.second << '\n';
  return 0;
}