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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ISTU: Ne nado dumat'
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int m = in.readInt();
            int totalGifts = 0;
            Bucket[] buckets = new Bucket[n];
            for (int i = 0; i < n; i++) {
                buckets[i] = new Bucket(i);
            }
            for (int i = 0; i < n; i++) {
                int k = in.readInt();
                totalGifts += k;
                for (int j = 0; j < k; j++) {
                    buckets[i].a.add(in.readInt());
                }
            }
            Arrays.sort(buckets);
            List<Move> moves = new ArrayList<>();
            for (int l = 0, r = n - 1; ; ) {
                while (l < n && buckets[l].a.size() == getNeedSize(l, n, totalGifts)) {
                    l++;
                }
                while (r >= 0 && buckets[r].a.size() == getNeedSize(r, n, totalGifts)) {
                    r--;
                }
                if (l > r) {
                    break;
                }
                int cnt = Math.min(
                        getNeedSize(l, n, totalGifts) - buckets[l].a.size(),
                        buckets[r].a.size() - getNeedSize(r, n, totalGifts)
                );
                List<Integer> kinds = get(buckets[l].a, buckets[r].a, cnt);
                for (int x : kinds) {
                    moves.add(new Move(buckets[r].index, buckets[l].index, x));
                    buckets[r].a.remove(x);
                    buckets[l].a.add(x);
                }
            }
            out.printLine(moves.size());
            for (int i = 0; i < moves.size(); i++) {
                Move move = moves.get(i);
                out.printFormat("%d %d %d\n", move.from + 1, move.to + 1, move.kind);
            }
        }

        int getNeedSize(int at, int n, int m) {
            if (m % n == 0) {
                return m / n;
            }
            int bigger = m % n;
            int prefix = n - bigger;
            if (at < prefix) {
                return m / n;
            }
            return m / n + 1;
        }

        List<Integer> get(TreeSet<Integer> s1, TreeSet<Integer> s2, int need) {
            if (need == 0) {
                return Collections.emptyList();
            }
            List<Integer> res = new ArrayList<>();
            Iterator<Integer> it1 = s1.iterator();
            Iterator<Integer> it2 = s2.iterator();
            int x = -1;
            while (it2.hasNext() && res.size() < need) {
                int y = it2.next();
                while (x < y) {
                    if (it1.hasNext()) {
                        x = it1.next();
                    } else {
                        x = Integer.MAX_VALUE;
                    }
                }
                if (x > y) {
                    res.add(y);
                }
            }
            return res;
        }

        class Move {
            int from;
            int to;
            int kind;

            Move(int from, int to, int kind) {
                this.from = from;
                this.to = to;
                this.kind = kind;
            }

        }

        class Bucket implements Comparable<Bucket> {
            int index;
            TreeSet<Integer> a = new TreeSet<>();

            Bucket(int index) {
                this.index = index;
            }

            public int compareTo(Bucket o) {
                return Integer.compare(a.size(), o.a.size());
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void printFormat(String format, Object... objects) {
            writer.printf(format, objects);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }
}