Problem: You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order.

Constraints

* 1 \leq N \leq 500,000
* 1 \leq M \leq 500,000
* 0 \leq a_i, b_i < N

Input

Input is given from Standard Input in the following format:


N M
a_0 b_0
a_1 b_1
:
a_{M - 1} b_{M - 1}


Output

Print 1+K lines, where K is the number of strongly connected components. Print K on the first line. Print the information of each strongly connected component in next K lines in the following format, where l is the number of vertices in the strongly connected component and v_i is the index of the vertex in it.


l v_0 v_1 ... v_{l-1}


Here, for each edge (a_i, b_i), b_i should not appear in earlier line than a_i.

If there are multiple correct output, print any of them.

Example

Input

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2


Output

4
1 5
2 4 1
1 2
2 3 0

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.nio.charset.Charset;
import java.util.NoSuchElementException;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.Collection;
import java.io.IOException;
import java.nio.charset.CharsetDecoder;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.io.UncheckedIOException;
import java.util.List;
import java.security.AccessControlException;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper reloaded plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner2 in = new LightScanner2(inputStream);
        LightWriter2 out = new LightWriter2(outputStream);
        SCC solver = new SCC();
        solver.solve(1, in, out);
        out.close();
    }

    static class SCC {
        public void solve(int testNumber, LightScanner2 in, LightWriter2 out) {
            int n = in.ints(), m = in.ints();
            SCC.Node[] nodes = new SCC.Node[n];
            for (int i = 0; i < n; i++) nodes[i] = new SCC.Node(i);
            for (int i = 0; i < m; i++) {
                int x = in.ints(), y = in.ints();
                nodes[x].next.add(nodes[y]);
                nodes[y].prev.add(nodes[x]);
            }
            List<? extends Collection<SCC.Node>> groups = SCCDecomposition.decompose(nodes);
            out.ans(groups.size()).ln();
            for (Collection<SCC.Node> group : groups) {
                out.ans(group.size());
                for (SCC.Node node : group) out.ans(node.getIndex());
                out.ln();
            }
        }

        private static class Node implements NodeLike<SCC.Node> {
            final int index;
            final List<SCC.Node> next = new ArrayList<>();
            final List<SCC.Node> prev = new ArrayList<>();

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

            public int getIndex() {
                return index;
            }

            public Collection<SCC.Node> getNextNodes() {
                return next;
            }

            public Collection<SCC.Node> getPrevNodes() {
                return prev;
            }

        }

    }

    static class SCCDecomposition {
        private SCCDecomposition() {
            throw new UnsupportedOperationException();
        }

        public static <T extends NodeLike<T>> List<? extends Collection<T>> decompose(T... nodes) {
            return decompose(Arrays.asList(nodes));
        }

        public static <T extends NodeLike<T>> List<? extends Collection<T>> decompose(List<T> nodes) {
            int n = nodes.size(), allocated = 0;
            boolean[] visited = new boolean[n];
            int[] counter = new int[n];
            for (int i = 0; i < n; i++) {
                if (visited[i]) continue;
                allocated = allocate(nodes.get(i), allocated, counter, visited);
            }
            int[] order = new int[n];
            for (int i = 0; i < n; i++) order[n - counter[i] - 1] = i;
            List<List<T>> result = new ArrayList<>();
            for (int i : order) {
                if (counter[i] == -1) continue;
                List<T> group = new ArrayList<>();
                makeGroup(nodes.get(i), counter, group);
                result.add(group);
            }
            return result;
        }

        private static int allocate(NodeLike<?> node, int allocated, int[] counter, boolean[] visited) {
            visited[node.getIndex()] = true;
            for (NodeLike<?> next : node.getNextNodes()) {
                if (visited[next.getIndex()]) continue;
                allocated = allocate(next, allocated, counter, visited);
            }
            counter[node.getIndex()] = allocated;
            return allocated + 1;
        }

        private static <T extends NodeLike<T>> void makeGroup(T node, int[] counter, List<T> group) {
            counter[node.getIndex()] = -1;
            group.add(node);
            for (T next : node.getPrevNodes()) {
                if (counter[next.getIndex()] == -1) continue;
                makeGroup(next, counter, group);
            }
        }

    }

    static class LightScanner2 extends LightScannerAdapter {
        private static final int BUF_SIZE = 32 * 1024;
        private final InputStream stream;
        private final byte[] buf = new byte[BUF_SIZE];
        private int ptr;
        private int len;

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

        private int read() {
            if (ptr < len) return buf[ptr++];
            try {
                ptr = 0;
                len = stream.read(buf);
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            if (len == -1) return -1;
            return buf[ptr++];
        }

        private void skip() {
            int b;
            while (isTokenSeparator(b = read()) && b != -1) ;
            if (b == -1) throw new NoSuchElementException("EOF");
            ptr--;
        }

        public int ints() {
            long x = longs();
            if (x < Integer.MIN_VALUE || Integer.MAX_VALUE < x) throw new NumberFormatException("Overflow");
            return (int) x;
        }

        public long longs() {
            skip();
            int b = read();
            boolean negate;
            if (b == '-') {
                negate = true;
                b = read();
            } else negate = false;
            long x = 0;
            for (; !isTokenSeparator(b); b = read()) {
                if ('0' <= b && b <= '9') x = x * 10 + b - '0';
                else throw new NumberFormatException("Unexpected character '" + b + "'");
            }
            return negate ? -x : x;
        }

        public void close() {
            try {
                stream.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        private static boolean isTokenSeparator(int b) {
            return b < 33 || 126 < b;
        }

    }

    static abstract class LightScannerAdapter implements AutoCloseable {
        public abstract void close();

    }

    static class LightWriter2 implements AutoCloseable {
        private static final int BUF_SIZE = 32 * 1024;
        private static final int BUF_THRESHOLD = 1024;
        private final OutputStream out;
        private final byte[] buf = new byte[BUF_SIZE];
        private int ptr;
        private final Field fastStringAccess;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter2(OutputStream out) {
            this.out = out;
            Field f;
            try {
                f = String.class.getDeclaredField("value");
                f.setAccessible(true);
                if (f.getType() != byte[].class) f = null;
            } catch (ReflectiveOperationException | AccessControlException ignored) {
                f = null;
            }
            this.fastStringAccess = f;
        }

        public LightWriter2(Writer out) {
            this.out = new LightWriter2.WriterOutputStream(out);
            this.fastStringAccess = null;
        }

        private void allocate(int n) {
            if (ptr + n <= BUF_SIZE) return;
            try {
                out.write(buf, 0, ptr);
                ptr = 0;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            if (BUF_SIZE < n) throw new IllegalArgumentException("Internal buffer exceeded");
        }

        public void close() {
            try {
                out.write(buf, 0, ptr);
                ptr = 0;
                out.flush();
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

        public LightWriter2 print(char c) {
            allocate(1);
            buf[ptr++] = (byte) c;
            breaked = false;
            return this;
        }

        public LightWriter2 print(String s) {
            byte[] bytes;
            if (this.fastStringAccess == null) bytes = s.getBytes();
            else {
                try {
                    bytes = (byte[]) fastStringAccess.get(s);
                } catch (IllegalAccessException ignored) {
                    bytes = s.getBytes();
                }
            }
            int n = bytes.length;
            if (n <= BUF_THRESHOLD) {
                allocate(n);
                System.arraycopy(bytes, 0, buf, ptr, n);
                ptr += n;
                return this;
            }
            try {
                out.write(buf, 0, ptr);
                ptr = 0;
                out.write(bytes);
                out.flush();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter2 ans(int i) {
            if (!breaked) {
                print(' ');
            }
            breaked = false;
            if (i == 0) return print('0');
            if (i < 0) {
                print('-');
                i = -i;
            }
            int n = 0;
            long t = i;
            while (t > 0) {
                t /= 10;
                n++;
            }
            allocate(n);
            for (int j = 1; j <= n; j++) {
                buf[ptr + n - j] = (byte) (i % 10 + '0');
                i /= 10;
            }
            ptr += n;
            return this;
        }

        public LightWriter2 ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        private static class WriterOutputStream extends OutputStream {
            final Writer writer;
            final CharsetDecoder decoder;

            WriterOutputStream(Writer writer) {
                this.writer = writer;
                this.decoder = StandardCharsets.UTF_8.newDecoder();
            }

            public void write(int b) throws IOException {
                writer.write(b);
            }

            public void write(byte[] b) throws IOException {
                writer.write(decoder.decode(ByteBuffer.wrap(b)).array());
            }

            public void write(byte[] b, int off, int len) throws IOException {
                writer.write(decoder.decode(ByteBuffer.wrap(b, off, len)).array());
            }

            public void flush() throws IOException {
                writer.flush();
            }

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

        }

    }

    static interface NodeLike<T extends NodeLike<T>> {
        int getIndex();

        Collection<T> getNextNodes();

        default Collection<T> getPrevNodes() {
            // default implementation for an *undirected* graph
            return getNextNodes();
        }

    }
}