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.*;
import java.util.*;
import java.math.*;
import java.lang.*;
 
import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        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 String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            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 long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long 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 double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } 
            while (!isSpaceChar(c));
            
            return res.toString();
        }
     
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
     
        public String next() {
            return readString();
        }
        
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();

        TreeSet<Integer> set[] = new TreeSet[n];
        for(int i = 0; i < n; ++i)
            set[i] = new TreeSet<>();

        int size[] = new int[n];
        int sum = 0;
        for(int i = 0; i < n; ++i) {
            size[i] = sc.nextInt();

            sum += size[i];

            for(int j = 0; j < size[i]; ++j)
                set[i].add(sc.nextInt());
        }

        int minReq = sum / n, maxReq = minReq + 1, maxPoss = sum % n;

        ArrayList<Integer> greaterIndices = new ArrayList<>();
        ArrayList<Integer> smallerIndices = new ArrayList<>();

        for(int i = 0; i < n; ++i) {
            if(size[i] <= minReq)
                smallerIndices.add(i);
            else
                greaterIndices.add(i);
        }

        int greaterPoss = min(maxPoss, greaterIndices.size()), lesserPoss = 0;
        if(greaterPoss < maxPoss)
            lesserPoss = maxPoss - greaterPoss;

        greaterPoss = greaterIndices.size() - greaterPoss;

        ArrayList<Move> moves = new ArrayList<>();

        int ptr = 0;
        ArrayList<Integer> removeList = new ArrayList<>();
        for(int i : smallerIndices) {
            while(size[i] < minReq || (size[i] == minReq && lesserPoss > 0)) {
                removeList.clear();
                int curInd = greaterIndices.get(ptr);

                int j = -1;

                while(set[curInd].higher(j) != null) {
                    j = set[curInd].higher(j);

                    if(!(size[i] < minReq || (size[i] == minReq && lesserPoss > 0)) || !(size[curInd] > maxReq || (size[curInd] == maxReq && greaterPoss > 0)))
                        break;

                    if(!set[i].contains(j)) {
                        removeList.add(j);

                        if(size[i] == minReq)
                            lesserPoss--;
                        if(size[curInd] == maxReq)
                            greaterPoss--;

                        size[i]++;
                        size[curInd]--;
                    }
                }

                for(int k : removeList) {
                    set[curInd].remove(k);
                    set[i].add(k);
                    moves.add(new Move(curInd, i, k));
                }

                if(size[i] < minReq || (size[i] == minReq && lesserPoss > 0)) 
                    ptr++;
            }
        }

        w.println(moves.size());
        for(Move curMove : moves)
            w.println(curMove);

        w.close();
    }
}
class Move {
    int from, to, kind;
    Move(int a, int b, int c) {
        from = a + 1;
        to = b + 1;
        kind = c;
    }
    public String toString() {
        return from + " " + to + " " + kind;
    }
}