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 namespace std;
const long double eps = 1e-5;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MXN = (int)1e5 + 7;
int hv[MXN];
int need[MXN];
int per[MXN];
struct Seg {
  int ll[MXN << 2], rr[MXN << 2];
  int a[MXN << 2], fr[MXN << 2];
  inline void pushup(int p) {
    if (a[p << 1] > a[p << 1 | 1]) {
      a[p] = a[p << 1];
      fr[p] = fr[p << 1];
    } else {
      a[p] = a[p << 1 | 1];
      fr[p] = fr[p << 1 | 1];
    }
  }
  void bd(int l, int r, int p = 1) {
    ll[p] = l, rr[p] = r;
    if (l == r) {
      a[p] = need[l] - hv[per[l]];
      fr[p] = l;
      return;
    }
    int mid = (l + r) >> 1;
    bd(l, mid, p << 1);
    bd(mid + 1, r, p << 1 | 1);
    pushup(p);
    return;
  }
  pair<int, int> qy(int l, int r, int p = 1) {
    if (l > rr[p] || r < ll[p]) return make_pair(-INF, 0);
    if (l <= ll[p] && rr[p] <= r) return make_pair(a[p], fr[p]);
    return max(qy(l, r, p << 1), qy(l, r, p << 1 | 1));
  }
  void md(int pp, int p = 1) {
    if (ll[p] == rr[p]) {
      a[p]--;
      return;
    }
    int mid = (ll[p] + rr[p]) >> 1;
    if (pp <= mid)
      md(pp, p << 1);
    else
      md(pp, p << 1 | 1);
    pushup(p);
  }
} seg;
set<int> al[MXN];
vector<int> st[MXN];
vector<int> al2[MXN];
bool cmp(const int &u, const int &v) { return hv[u] < hv[v]; }
vector<pair<pair<int, int>, int>> ans;
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int sum = 0;
  for (int i = 1; i < n + 1; ++i) per[i] = i;
  for (int i = 1; i < n + 1; ++i) {
    int num;
    scanf("%d", &num);
    hv[i] = num;
    sum += num;
    while (num--) {
      int v;
      scanf("%d", &v);
      st[i].push_back(v);
    }
  }
  sort(per + 1, per + n + 1, cmp);
  for (int i = 1; i < n + 1; ++i) need[i] = sum / n;
  for (int i = n + 1 - sum % n; i < n + 1; ++i) need[i]++;
  seg.bd(1, n);
  for (int i = 1; i < n + 1; ++i) {
    int id = per[i];
    if (need[i] > hv[id]) {
      for (int v : st[id]) al[v].insert(i);
    } else if (need[i] < hv[id]) {
      for (int v : st[id]) al2[v].push_back(i);
    }
  }
  for (int i = 1; i < m + 1; ++i) {
    al[i].insert(0);
    al[i].insert(n + 1);
  }
  for (int i = 1; i < m + 1; ++i) {
    auto ll = al[i].begin();
    auto rr = ll;
    rr++;
    for (int u : al2[i]) {
      if (need[u] == hv[per[u]]) continue;
      while (rr != al[i].end()) {
        int l = *ll, r = *rr;
        if (l + 1 > r - 1) {
          ll++, rr++;
        } else {
          pair<int, int> res = seg.qy(l + 1, r - 1);
          if (res.first > 0) {
            int p = res.second;
            seg.md(p);
            ans.push_back(make_pair(make_pair(per[u], per[p]), i));
            hv[per[u]]--;
            al[i].insert(p);
            ll = al[i].lower_bound(l);
            rr = al[i].lower_bound(p);
            break;
          } else {
            ll++;
            rr++;
          }
        }
      }
    }
  }
  printf("%d\n", (int)(ans).size());
  for (auto x : ans)
    printf("%d %d %d\n", x.first.first, x.first.second, x.second);
  return 0;
}