Problem: Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct.

Having packed all the presents, Santa realized that different boxes can contain different number of presents. It would be unfair to the children, so he decided to move some presents between boxes, and make their sizes similar. After all movements, the difference between the maximal and the minimal number of presents in a box must be as small as possible. All presents in each box should still be distinct. Santa wants to finish the job as fast as possible, so he wants to minimize the number of movements required to complete the task.

Given the sets of presents in each box, find the shortest sequence of movements of presents between boxes that minimizes the difference of sizes of the smallest and the largest box, and keeps all presents in each box distinct.

Input

The first line of input contains two integers n, m (1 ≤ n, m ≤ 100\ 000), the number of boxes and the number of kinds of the presents. Denote presents with integers from 1 to m.

Each of the following n lines contains the description of one box. It begins with an integer s_i (s_i ≥ 0), the number of presents in the box, s_i distinct integers between 1 and m follow, denoting the kinds of presents in that box.

The total number of presents in all boxes does not exceed 500 000.

Output

Print one integer k at the first line of output, the number of movements in the shortest sequence that makes the sizes of the boxes differ by at most one. Then print k lines that describe movements in the same order in which they should be performed. Each movement is described by three integers from_i, to_i, kind_i. It means that the present of kind kind_i is moved from the box with number from_i to the box with number to_i. Boxes are numbered from one in the order they are given in the input.

At the moment when the movement is performed the present with kind kind_i must be present in the box with number from_i. After performing all moves each box must not contain two presents of the same kind.

If there are several optimal solutions, output any of them.

Example

Input


3 5
5 1 2 3 4 5
2 1 2
2 3 4


Output


2
1 3 5
1 2 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using std::vector;
vector<int> box[100005];
int order[100005];
int need[100005];
int cur[100005];
int used[100005];
struct Result {
  int from, to, kind;
  Result() {}
  Result(int from, int to, int kind) : from(from), to(to), kind(kind) {}
};
Result answer[500005];
int min(int a, int b) { return a > b ? b : a; }
struct SegmentT {
  int l, r;
  int d;
  int fst;
};
SegmentT t[400005];
SegmentT merge(SegmentT& u, SegmentT& v) {
  SegmentT res;
  res.l = u.l, res.r = v.r;
  res.d = res.fst = -1;
  if (u.fst != -1)
    res.fst = u.fst;
  else
    res.fst = v.fst;
  return res;
}
void build(int p, int l, int r) {
  t[p].l = l, t[p].r = r;
  if (l == r) {
    t[p].d = 0;
    t[p].fst = -1;
  } else {
    int m = (l + r) / 2;
    build(2 * p, l, m);
    build(2 * p + 1, m + 1, r);
    t[p] = merge(t[2 * p], t[2 * p + 1]);
  }
}
void change(int p, int x, int v) {
  if (t[p].l == t[p].r) {
    t[p].d += v;
    if (t[p].d == 1)
      t[p].fst = t[p].l;
    else
      t[p].fst = -1;
  } else {
    int m = (t[p].l + t[p].r) / 2;
    if (x <= m)
      change(2 * p, x, v);
    else
      change(2 * p + 1, x, v);
    t[p] = merge(t[2 * p], t[2 * p + 1]);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int all = 0;
  for (int i = 1; i <= n; i++) {
    order[i] = i;
    int k;
    scanf("%d", &k);
    all += k;
    cur[i] = k;
    while (k--) {
      int u;
      scanf("%d", &u);
      box[i].push_back(u);
    }
  }
  std::sort(order + 1, order + 1 + n,
            [&](int& u, int& v) { return box[u].size() < box[v].size(); });
  int left = all % n;
  int base = all / n;
  for (int i = 1; i <= n; i++) {
    int p = order[n - i + 1];
    if (i <= left)
      need[p] = base + 1;
    else
      need[p] = base;
  }
  build(1, 1, m);
  int total = 0;
  int l = 1, r = n;
  for (int u : box[order[l]]) {
    change(1, u, -1);
  }
  for (int u : box[order[r]]) {
    used[u] = 0;
    change(1, u, 1);
  }
  while (l < r) {
    while (l <= n && cur[order[l]] == need[order[l]]) {
      for (int u : box[order[l]]) change(1, u, 1);
      l++;
      if (l != n + 1) {
        for (int u : box[order[l]]) change(1, u, -1);
      }
    }
    while (r >= 1 && cur[order[r]] == need[order[r]]) {
      for (int u : box[order[r]]) {
        if (!used[u]) change(1, u, -1);
      }
      r--;
      if (r != 0) {
        for (int u : box[order[r]]) {
          used[u] = 0;
          change(1, u, 1);
        }
      }
    }
    if (l >= r) break;
    int give =
        min(cur[order[r]] - need[order[r]], need[order[l]] - cur[order[l]]);
    for (int rnd = 0; rnd < give; rnd++) {
      int kind = t[1].fst;
      change(1, kind, -2);
      box[order[l]].push_back(kind);
      used[kind] = 1;
      answer[++total] = Result(order[r], order[l], kind);
      cur[order[l]]++;
      cur[order[r]]--;
    }
  }
  printf("%d\n", total);
  for (int i = 1; i <= total; i++)
    printf("%d %d %d\n", answer[i].from, answer[i].to, answer[i].kind);
  return 0;
}