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 int maxn = 100005;
int n, m, vis[maxn];
struct out {
  int f, t, k;
  out() {}
  out(int f, int t, int k) : f(f), t(t), k(k) {}
};
set<pair<int, int> > S;
set<pair<int, int> >::iterator it;
set<int> G[maxn];
int nu[maxn], a[maxn], sum;
vector<out> ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)1; i <= (int)n; i++) {
    scanf("%d", &nu[i]);
    for (int j = (int)1; j <= (int)nu[i]; j++) {
      int x;
      scanf("%d", &x);
      G[i].insert(x);
    }
    S.insert({nu[i], i});
    sum += nu[i];
  }
  int cha, ma, mi;
  if (sum % n == 0) {
    ma = mi = sum / n;
    cha = 0;
  } else {
    mi = sum / n, ma = mi + 1;
    cha = 1;
  }
  if (n == 1) {
    return 0 * printf("0\n");
  }
  pair<int, int> bi, sm;
  it = S.begin();
  sm = *it;
  S.erase(it);
  it = S.end();
  it--;
  bi = *it;
  S.erase(it);
  int br = 0;
  while (1 && !br) {
    vector<int> tmp, tmp1;
    if (bi.first - sm.first <= cha) break;
    int szb = G[bi.second].size(), szs = G[sm.second].size();
    int tb = szb, ts = szs, f1 = 0, f2 = 0;
    for (set<int>::iterator is = G[sm.second].begin(); is != G[sm.second].end();
         is++) {
      int th = *is;
      a[th]--;
    }
    for (set<int>::iterator is = G[bi.second].begin(); is != G[bi.second].end();
         is++) {
      int th = *is;
      a[th]++;
      tmp1.push_back(th);
      if (a[th] == 1) {
        ans.push_back({bi.second, sm.second, th});
        tb--, ts++;
        tmp.push_back(th);
        if (tb <= mi + cha) f1 = 1;
        if (ts >= ma - cha) f2 = 1;
        if (f1 && f2 || tb == mi || ts == ma) break;
      }
    }
    for (int i = 0; i < tmp.size(); i++) {
      int th = tmp[i];
      G[sm.second].insert(th);
      G[bi.second].erase(th);
    }
    if (f1 && f2) {
      for (int i = 0; i < tmp1.size(); i++) {
        a[tmp1[i]]--;
      }
      for (set<int>::iterator is = G[sm.second].begin();
           is != G[sm.second].end(); is++) {
        int th = *is;
        a[th] = 0;
      }
      if (S.size()) {
        it = S.begin();
        sm = *it;
        S.erase(it);
      } else
        br = 1;
      if (S.size()) {
        it = S.end();
        it--;
        bi = *it;
        S.erase(it);
      } else
        br = 1;
    } else if (tb == mi) {
      for (int i = 0; i < tmp1.size(); i++) {
        a[tmp1[i]]--;
      }
      if (S.size()) {
        it = S.end();
        it--;
        bi = *it;
        S.erase(it);
      } else
        br = 1;
    } else {
      for (int i = 0; i < tmp1.size(); i++) {
        a[tmp1[i]]--;
      }
      for (set<int>::iterator is = G[sm.second].begin();
           is != G[sm.second].end(); is++) {
        int th = *is;
        a[th] = 0;
      }
      if (S.size()) {
        it = S.begin();
        sm = *it;
        S.erase(it);
      } else
        br = 1;
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    out x = ans[i];
    printf("%d %d %d\n", x.f, x.t, x.k);
  }
  return 0;
}