import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DChaoticV solver = new DChaoticV();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DChaoticV {
        int limit = 669;
        Node[] nodes;
        int n;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            EulerSieve es = new EulerSieve(5000);
            nodes = new Node[5000 + 1];
            for (int i = 1; i <= 5000; i++) {
                nodes[i] = new Node();
                nodes[i].id = i;
            }

            n = in.readInt();
            for (int i = 1; i <= 5000; i++) {
                for (int j = 0; j < limit; j++) {
                    nodes[i].status[j] = countFactor(i, es.get(j));
                }
            }

            for (int i = 0; i < n; i++) {
                int which = in.readInt();
                if (which == 0) {
                    which = 1;
                }
                nodes[which].weight++;
            }
            rec(nodes.clone(), 1, 5000, limit - 1);
            dfs(nodes[1], null);
            Node center = findCenter(nodes[1], null, nodes[1].size);
            int ans = count(center, null, 0);
            out.println(ans);
        }

        public int count(Node root, Edge p, int depth) {
            int ans = root.weight * depth;
            for (Edge e : root.next) {
                if (e == p) {
                    continue;
                }
                Node node = e.other(root);
                ans += count(node, e, depth + e.len);
            }
            return ans;
        }

        public Node findCenter(Node root, Edge p, int total) {
            int maxChild = total - root.size;
            for (Edge e : root.next) {
                if (e == p) {
                    continue;
                }
                Node node = e.other(root);
                maxChild = Math.max(maxChild, node.size);
            }
            if (maxChild * 2 <= total) {
                return root;
            }
            for (Edge e : root.next) {
                if (e == p) {
                    continue;
                }
                Node node = e.other(root);
                Node ans = findCenter(node, e, total);
                if (ans != null) {
                    return ans;
                }
            }
            return null;
        }

        public void dfs(Node root, Edge p) {
            root.size = root.weight;
            for (Edge e : root.next) {
                if (e == p) {
                    continue;
                }
                Node node = e.other(root);
                dfs(node, e);
                root.size += node.size;
            }
        }

        public Node rec(Node[] nodes, int l, int r, int k) {
            if (k < 0) {
                return nodes[l];
            }
            Arrays.sort(nodes, l, r + 1, (a, b) -> a.status[k] - b.status[k]);
            Node last = null;
            for (int i = r; i >= l; i--) {
                int j = i;
                while (i - 1 >= l && nodes[i - 1].status[k] == nodes[i].status[k]) {
                    i--;
                }
                Node merged = rec(nodes, i, j, k - 1);
                if (last == null) {
                    last = merged;
                } else {
                    last = merge(last, merged);
                }
            }
            return last;
        }

        public Node merge(Node a, Node b) {
            Node merged = new Node();
            for (int i = limit - 1; i >= 0; i--) {
                if (a.status[i] == b.status[i]) {
                    merged.status[i] = a.status[i];
                } else {
                    if (a.status[i] > b.status[i]) {
                        Node tmp = a;
                        a = b;
                        b = tmp;
                    }
                    merged.status[i] = a.status[i];
                    int distToA = 0;
                    int distToB = b.status[i] - a.status[i];
                    for (int j = 0; j < i; j++) {
                        distToA += a.status[j];
                        distToB += b.status[j];
                    }
                    if (distToA > 0) {
                        addEdge(merged, a, distToA);
                        addEdge(merged, b, distToB);
                        return merged;
                    } else {
                        addEdge(a, b, distToB);
                        return a;
                    }
                }
            }

            throw new RuntimeException();
        }

        public void addEdge(Node a, Node b, int len) {
            Edge e = new Edge();
            e.a = a;
            e.b = b;
            e.len = len;
            a.next.add(e);
            b.next.add(e);
        }

        public int countFactor(int n, int x) {
            return n <= 0 ? 0 : (n / x + countFactor(n / x, x));
        }

    }

    static class FastOutput implements AutoCloseable, Closeable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

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

        public String toString() {
            return cache.toString();
        }

    }

    static class Node {
        List<Edge> next = new ArrayList<>();
        int size;
        int id;
        int weight;
        int[] status = new int[669];

        public String toString() {
            return "" + id;
        }

    }

    static class EulerSieve {
        private int[] primes;
        private boolean[] isComp;
        private int primeLength;

        public int get(int k) {
            return primes[k];
        }

        public EulerSieve(int limit) {
            isComp = new boolean[limit + 1];
            primes = new int[limit + 1];
            primeLength = 0;
            for (int i = 2; i <= limit; i++) {
                if (!isComp[i]) {
                    primes[primeLength++] = i;
                }
                for (int j = 0, until = limit / i; j < primeLength && primes[j] <= until; j++) {
                    int pi = primes[j] * i;
                    isComp[pi] = true;
                    if (i % primes[j] == 0) {
                        break;
                    }
                }
            }
        }

    }

    static class Edge {
        Node a;
        Node b;
        int len;

        Node other(Node x) {
            return a == x ? b : a;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}

Æsir - CHAOS Æsir - V."Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect.The time right now...... 00:01:12......It's time."The emotion samples are now sufficient. After almost 3 years, it's time for Ivy to awake her bonded sister, Vanessa.The system inside A.R.C.'s Library core can be considered as an undirected graph with infinite number of processing nodes, numbered with all positive integers ($$$1, 2, 3, \ldots$$$). The node with a number $$$x$$$ ($$$x > 1$$$), is directly connected with a node with number $$$\frac{x}{f(x)}$$$, with $$$f(x)$$$ being the lowest prime divisor of $$$x$$$.Vanessa's mind is divided into $$$n$$$ fragments. Due to more than 500 years of coma, the fragments have been scattered: the $$$i$$$-th fragment is now located at the node with a number $$$k_i!$$$ (a factorial of $$$k_i$$$).To maximize the chance of successful awakening, Ivy decides to place the samples in a node $$$P$$$, so that the total length of paths from each fragment to $$$P$$$ is smallest possible. If there are multiple fragments located at the same node, the path from that node to $$$P$$$ needs to be counted multiple times.In the world of zeros and ones, such a requirement is very simple for Ivy. Not longer than a second later, she has already figured out such a node.But for a mere human like you, is this still possible?For simplicity, please answer the minimal sum of paths' lengths from every fragment to the emotion samples' assembly node $$$P$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — number of fragments of Vanessa's mind. The second line contains $$$n$$$ integers: $$$k_1, k_2, \ldots, k_n$$$ ($$$0 \le k_i \le 5000$$$), denoting the nodes where fragments of Vanessa's mind are located: the $$$i$$$-th fragment is at the node with a number $$$k_i!$$$.

Print a single integer, denoting the minimal sum of path from every fragment to the node with the emotion samples (a.k.a. node $$$P$$$). As a reminder, if there are multiple fragments at the same node, the distance from that node to $$$P$$$ needs to be counted multiple times as well.

NoteConsidering the first $$$24$$$ nodes of the system, the node network will look as follows (the nodes $$$1!$$$, $$$2!$$$, $$$3!$$$, $$$4!$$$ are drawn bold):For the first example, Ivy will place the emotion samples at the node $$$1$$$. From here:  The distance from Vanessa's first fragment to the node $$$1$$$ is $$$1$$$.  The distance from Vanessa's second fragment to the node $$$1$$$ is $$$0$$$.  The distance from Vanessa's third fragment to the node $$$1$$$ is $$$4$$$. The total length is $$$5$$$.For the second example, the assembly node will be $$$6$$$. From here:  The distance from Vanessa's first fragment to the node $$$6$$$ is $$$0$$$.  The distance from Vanessa's second fragment to the node $$$6$$$ is $$$2$$$.  The distance from Vanessa's third fragment to the node $$$6$$$ is $$$2$$$.  The distance from Vanessa's fourth fragment to the node $$$6$$$ is again $$$2$$$. The total path length is $$$6$$$.

import java.io.*;
import java.util.*;

public class Akisolution {
	public static Scanner sc = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out, true);
	public static final int MAXK = 5000;
	public static int n;
	public static int[] cnt = new int[MAXK + 1];
	public static int[][] primeExponential = new int[MAXK + 1][MAXK + 1];

	public static long min(long a, long b) {return ((a < b) ? a : b);}

	public static int max_element(int[] arr) {
		int res = -1000000000;
		for (int i=0; i<arr.length; i++) {
			if (arr[i] > res) res = arr[i];
		}
		return res;
	}

	public static int max_id(int[] arr) {
		int res = -1000000000, id = -1;
		for (int i=0; i<arr.length; i++) {
			if (arr[i] > res) {
				res = arr[i];
				id = i;
			}
		}
		return id;
	}

	public static void Preprocess() {
		for (int i=2; i<MAXK + 1; i++) {
			for (int j=0; j<MAXK + 1; j++) primeExponential[i][j] += primeExponential[i-1][j];
			int tmp = i;
			for (int x=2; x<=Math.sqrt(tmp); x++) {
				while (tmp % x == 0) {primeExponential[i][x]++; tmp /= x;}
			}
			if (tmp > 1) primeExponential[i][tmp]++;
		}
	}

	public static void Input() {
		n = sc.nextInt();
		for (int i=0; i<n; i++) {
			int k = sc.nextInt();
			cnt[k] += 1;
		}
	}

	public static void Solve() {
		Preprocess();

		int[] bestPD = new int[MAXK + 1];
		for (int i=0; i<MAXK + 1; i++) bestPD[i] = 1;
		long ans = 0, cur = 0;
		for (int i=1; i<MAXK + 1; i++) {
			if (cnt[i] == 0) {bestPD[i] = 1; continue;}
			for (int j=1; j<MAXK + 1; j++) {
				ans += (long)primeExponential[i][j] * cnt[i];
				cur += (long)primeExponential[i][j] * cnt[i];
				if (primeExponential[i][j] != 0) bestPD[i] = j;
			}
		}

		while (max_element(bestPD) > 1) {
			int[] frequency = new int[MAXK + 1];

			for (int i=0; i<MAXK + 1; i++) frequency[bestPD[i]] += cnt[i];

			int bestPrime = max_id(frequency);
			int bestGroup = frequency[bestPrime];
			if (bestGroup * 2 <= n) break;
			if (bestPrime == 1) break;
			cur -= bestGroup; cur += (n - bestGroup); ans = min(ans, cur);

			for (int i=0; i<MAXK + 1; i++) {
				if (bestPD[i] != bestPrime) bestPD[i] = 1;
				if (bestPD[i] == 1) continue;
				primeExponential[i][bestPD[i]] -= 1;
				while (bestPD[i] > 1 && primeExponential[i][bestPD[i]] == 0) bestPD[i]--;
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		Input(); Solve();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            char[][] puzzle = new char[A][B];
            for (int i = 0; i < A; i++) {
                puzzle[i] = in.next().toCharArray();
            }
            PriorityQueue<piece> ans = new PriorityQueue<>();
            for (int Y = 1; Y <= A; Y++) {
                for (int X = 1; X <= B; X++) {
                    if (A % Y == 0 && B % X == 0) {
                        if (chk(puzzle, Y, X)) {
                            ans.offer(new piece(Y, X));
                        }
                    }
                }
            }
            out.println(ans.size());
            out.println(ans.peek());
        }

        boolean chk(char[][] puzzle, int Y, int X) {
            TreeSet<fullPiece> pieces = new TreeSet<>();
            for (int i = 0; i < puzzle.length; i += Y) {
                for (int j = 0; j < puzzle[0].length; j += X) {
                    pieces.add(new fullPiece(puzzle, Y, X, i, j));
                }
            }
            int all = puzzle.length / Y;
            all *= puzzle[0].length / X;
            if (pieces.size() == all) {
                return true;
            }
            return false;
        }

    }

    static class piece implements Comparable {
        int y;
        int x;

        piece(int y1, int x1) {
            y = y1;
            x = x1;
        }

        public int compareTo(Object o) {
            piece other = (piece) o;
            int oS = other.x * other.y;
            int S = x * y;
            if (S == oS) {
                return y - other.y;
            }
            return S - oS;
        }

        public String toString() {
            return y + " " + x;
        }

    }

    static class fullPiece implements Comparable {
        char[][] data;

        fullPiece(char[][] puzzle, int Y, int X, int top, int left) {
            data = new char[Y][X];
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    data[i][j] = puzzle[i + top][j + left];
                }
            }
        }

        public int compareTo(Object o) {
            fullPiece other = (fullPiece) o;
            if (eq(other)) {
                return 0;
            }
            return comp(other);
        }

        private int comp(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[i][j] > other.data[i][j]) return 1;
                    if (data[i][j] < other.data[i][j]) return -1;
                }
            }
            return 0;
        }

        private boolean eq(fullPiece other) {
            return eq0(other) || eq90(other) || eq180(other) || eq270(other);
        }

        private boolean eq0(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[i][j] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq180(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[Y - i - 1][X - j - 1] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq90(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            if (other.data[0].length != Y) return false;
            if (other.data.length != X) return false;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[j][Y - i - 1] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq270(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            if (other.data[0].length != Y) return false;
            if (other.data.length != X) return false;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[X - j - 1][i] != other.data[i][j]) return false;
                }
            }
            return true;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one.Soon the Hedgehog came up with a brilliant idea: instead of buying ready-made puzzles, one can take his own large piece of paper with some picture and cut it into many small rectangular pieces, then mix them and solve the resulting puzzle, trying to piece together the picture. The resulting task is even more challenging than the classic puzzle: now all the fragments have the same rectangular shape, and one can assemble the puzzle only relying on the picture drawn on the pieces.All puzzle pieces turn out to be of the same size X × Y, because the picture is cut first by horizontal cuts with the pitch of X, then with vertical cuts with the pitch of Y. If we denote the initial size of the picture as A × B, then A must be divisible by X and B must be divisible by Y (X and Y are integer numbers). However, not every such cutting of the picture will result in a good puzzle. The Hedgehog finds a puzzle good if no two pieces in it are the same (It is allowed to rotate the pieces when comparing them, but it is forbidden to turn them over). Your task is to count for a given picture the number of good puzzles that you can make from it, and also to find the puzzle with the minimal piece size.

The first line contains two numbers A and B which are the sizes of the picture. They are positive integers not exceeding 20. Then follow A lines containing B symbols each, describing the actual picture. The lines only contain uppercase English letters.

In the first line print the number of possible good puzzles (in other words, the number of pairs (X, Y) such that the puzzle with the corresponding element sizes will be good). This number should always be positive, because the whole picture is a good puzzle itself.  In the second line print two numbers — the sizes X and Y of the smallest possible element among all good puzzles. The comparison is made firstly by the area XY of one element and secondly — by the length X.

NoteThe picture in the first sample test has the following good puzzles: (2, 1), (2, 2), (2, 4).

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            char[][] puzzle = new char[A][B];
            for (int i = 0; i < A; i++) {
                puzzle[i] = in.next().toCharArray();
            }
            PriorityQueue<piece> ans = new PriorityQueue<>();
            for (int Y = 1; Y <= A; Y++) {
                for (int X = 1; X <= B; X++) {
                    if (A % Y == 0 && B % X == 0) {
                        if (chk(puzzle, Y, X)) {
                            ans.offer(new piece(Y, X));
                        }
                    }
                }
            }
            out.println(ans.size());
            out.println(ans.peek());
        }

        boolean chk(char[][] puzzle, int Y, int X) {
            ArrayList<fullPiece> pieces = new ArrayList<>();
            for (int i = 0; i < puzzle.length; i += Y) {
                for (int j = 0; j < puzzle[0].length; j += X) {
                    fullPiece next = new fullPiece(puzzle, Y, X, i, j);
                    for (fullPiece cur : pieces) {
                        if (next.eq(cur)) return false;
                    }
                    pieces.add(next);
                }
            }
            return true;
        }

    }

    static class piece implements Comparable {
        int y;
        int x;

        piece(int y1, int x1) {
            y = y1;
            x = x1;
        }

        public int compareTo(Object o) {
            piece other = (piece) o;
            int oS = other.x * other.y;
            int S = x * y;
            if (S == oS) {
                return y - other.y;
            }
            return S - oS;
        }

        public String toString() {
            return y + " " + x;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class fullPiece {
        char[][] data;

        fullPiece(char[][] puzzle, int Y, int X, int top, int left) {
            data = new char[Y][X];
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    data[i][j] = puzzle[i + top][j + left];
                }
            }
        }

        public boolean eq(fullPiece other) {
            return eq0(other) || eq90(other) || eq180(other) || eq270(other);
        }

        private boolean eq0(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[i][j] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq180(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[Y - i - 1][X - j - 1] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq90(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            if (other.data[0].length != Y) return false;
            if (other.data.length != X) return false;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[X - j - 1][i] != other.data[i][j]) return false;
                }
            }
            return true;
        }

        private boolean eq270(fullPiece other) {
            int Y = data.length;
            int X = data[0].length;
            if (other.data[0].length != Y) return false;
            if (other.data.length != X) return false;
            for (int i = 0; i < Y; i++) {
                for (int j = 0; j < X; j++) {
                    if (data[j][Y - i - 1] != other.data[i][j]) return false;
                }
            }
            return true;
        }

    }
}

[{'input': '2 4\r\nABDC\r\nABDC\r\n', 'output': ['3\r\n2 1\r\n']}, {'input': '2 6\r\nABCCBA\r\nABCCBA\r\n', 'output': ['1\r\n2 6\r\n']}, {'input': '2 2\r\nAB\r\nCD\r\n', 'output': ['4\r\n1 1\r\n']}, {'input': '4 6\r\nABABAC\r\nBABABC\r\nABABAC\r\nCCCCCA\r\n', 'output': ['4\r\n2 3\r\n']}, {'input': '1 12\r\nABAAADCAAABX\r\n', 'output': ['4\r\n1 3\r\n']}, {'input': '4 6\r\nABCDEF\r\nGHIJKL\r\nMNOPQR\r\nSTUVWX\r\n', 'output': ['12\r\n1 1\r\n']}, {'input': '5 5\r\nABAAA\r\nBBBAA\r\nABABA\r\nBBABB\r\nBAAAB\r\n', 'output': ['3\r\n1 5\r\n']}, {'input': '5 6\r\nBBBABB\r\nAAAABB\r\nABABAA\r\nABBBAA\r\nBABBBA\r\n', 'output': ['4\r\n1 6\r\n']}, {'input': '7 7\r\nBBAAABB\r\nAABBBBA\r\nAABABBA\r\nAABABAB\r\nAABBBAA\r\nBAAAABA\r\nBBABBBB\r\n', 'output': ['3\r\n1 7\r\n']}, {'input': '8 7\r\nBABABBB\r\nABABABA\r\nAABBABA\r\nABBABAA\r\nBABAAAB\r\nAABBBBA\r\nABBBBAB\r\nBBAAABA\r\n', 'output': ['5\r\n1 7\r\n']}, {'input': '8 9\r\nBAABABAAB\r\nBAABAAAAB\r\nBBBBBAABB\r\nAAAAAAAAB\r\nBABBABBAA\r\nBBABABBBB\r\nBABABBAAA\r\nAABAABBBB\r\n', 'output': ['7\r\n8 1\r\n']}, {'input': '10 10\r\nABBAABAABB\r\nABAAAAAABA\r\nBAABABABAA\r\nBAAAAAAAAB\r\nBABABBBAAB\r\nABBABBBBBA\r\nAABABAAAAA\r\nBAAAABAABA\r\nABABAABBAA\r\nBBABBABABB\r\n', 'output': ['9\r\n1 10\r\n']}, {'input': '10 11\r\nABBBAABABBB\r\nBBAABABBAAB\r\nAABBBBBAAAA\r\nBBABABAAABA\r\nAABABBBAABB\r\nAAABABAABAB\r\nBBABBBABBBB\r\nBBABABABBAA\r\nBBABABAAABB\r\nBABAABAABAB\r\n', 'output': ['5\r\n10 1\r\n']}, {'input': '12 11\r\nBBAAAABBAAB\r\nBBABBABBABB\r\nBAABABBABBA\r\nBABBBAAAABA\r\nABBAABBBBBA\r\nABBABBABABB\r\nAAABBBABBBB\r\nBAABAAABAAA\r\nAAAABBBBABA\r\nAAABAAABBBB\r\nBAAAAABABAB\r\nABBBBABABBB\r\n', 'output': ['7\r\n1 11\r\n']}, {'input': '12 13\r\nBBABABAAAAABA\r\nABAAAAAAAABBA\r\nABBBABAAAAABA\r\nBBBAABABBABBB\r\nABABAAABABABB\r\nABBAABAABBAAA\r\nAABABBAAABBAB\r\nABBBBBABBAABA\r\nBBBBBABBABBAA\r\nAAAAAAABBBAAB\r\nBAABBBAABAAAA\r\nBBBBBBABABABA\r\n', 'output': ['7\r\n12 1\r\n']}, {'input': '14 12\r\nBBAAABBBAAAB\r\nBBABAAAAABAA\r\nAABBABBBABBA\r\nBABAABAABBBB\r\nBBBABBBBABAA\r\nABBAABBAAABA\r\nABAAAAABBBAB\r\nBBAABBABBBAA\r\nBAABABAAABAB\r\nAAABBBABBABA\r\nBABBBBAABBBA\r\nAAAAABABBAAB\r\nBABBBABBBBBA\r\nBAAAABAABAAA\r\n', 'output': ['14\r\n1 12\r\n']}, {'input': '14 10\r\nABBAAABBAA\r\nBBBBBABBAA\r\nBABABBABAB\r\nAAABABBAAB\r\nBBABABBBAB\r\nBBABBABABB\r\nAABBBBABAA\r\nABBBAAAABB\r\nABBABAABAA\r\nABABABABBA\r\nABAABBBAAB\r\nAAAAAAAAAA\r\nABABBAABAA\r\nBABAABABBB\r\n', 'output': ['10\r\n1 10\r\n']}, {'input': '16 15\r\nABBBBAAABABBABB\r\nABBBAAABBABBBBB\r\nBABABAABBBABABB\r\nAAABBBBBABBABBB\r\nBAABAABAABAABBA\r\nABBBBAAAAAAAABB\r\nBAABBBABABAAAAB\r\nAAAABBAABBAABAA\r\nABBABABAAABABBB\r\nAAABBBABAABABAA\r\nBAABABBAAABBAAA\r\nAAAAAAABABBBAAA\r\nBABBAABBABAAAAB\r\nABABAAABBBBBAAB\r\nBBABBAABABAABBB\r\nBAAAABBBABABBBA\r\n', 'output': ['12\r\n4 3\r\n']}, {'input': '16 16\r\nABBABBABBAABBBAB\r\nBABABBAABAABBAAA\r\nBAAABBAABAABBBAA\r\nAABAAAABAAAABBBA\r\nBAAAABAABBBABBAA\r\nAABBABABABAABBBA\r\nBABBBABAAAAABABB\r\nBABBBBBBBBABBBAB\r\nBAAAABBBABAABBBA\r\nBABBBABBAABABBAA\r\nBBBBBBAABBBABBBA\r\nBABAAAABAABAABBB\r\nAAAAABBAAABABAAA\r\nBABBABABABAAABAB\r\nBAAAAAAAABBABAAA\r\nBAAAAABABBBBAAAA\r\n', 'output': ['15\r\n1 16\r\n']}, {'input': '18 18\r\nBBBBBBBABABBBABABA\r\nBAAABAAABBBABABBBB\r\nBABBAAABAAABAAABAA\r\nAABBABBBABBBBBAAAB\r\nBBBAAAAABBABBAAAAA\r\nAABBAABABABBBABABA\r\nBAABBAAAABABAABABB\r\nBABBABBBAAAABAABBA\r\nBBBBAABAAABAAABBBA\r\nABABBAAABBBBBABABA\r\nABABAABBBBBABBBBBB\r\nABAAABBABBABAAAABA\r\nBABAAABABABBBABBBB\r\nBBBBABBBABBBBBBBBA\r\nBAAABAABABABBBBAAB\r\nBABBAABABBABAABBBB\r\nBAABABAAAABBABBAAA\r\nBAAABBBAABABBABBAB\r\n', 'output': ['23\r\n2 6\r\n']}, {'input': '17 17\r\nBBAABAABBBBBAABBB\r\nBBABABBBBABAAABBB\r\nAAAABAAAABABABBAA\r\nBBABAAABBABBAAABA\r\nAAABBBBBAABABBBAB\r\nAABBBBBABABABABBB\r\nBAABAAABAAABBAABB\r\nBBAAAAAABABABBAAB\r\nAAAAABAABBAAAABAA\r\nBABAABABABABABBBB\r\nBAABABBAAABBAAABB\r\nABBAAABBBBAAAABAB\r\nBBABAABAAAAAABBBB\r\nAAABBABBAAAAABBBB\r\nAABAABBAABBABAABB\r\nABABAAABBABAAABAB\r\nBBABABBBAAAAAAABA\r\n', 'output': ['3\r\n1 17\r\n']}, {'input': '20 20\r\nABBBAAABABAAAAABBABB\r\nBABABBAABAABBAAABABB\r\nBABBBAABAABBABBBBABA\r\nBAAABBAAABABBABBAAAA\r\nABBAABAABBBBAAABBBAA\r\nBAAAAAAAABABBAAAAABB\r\nAAAAAAABABBBBBAABAAB\r\nABBBBABAABBAAAAABAAA\r\nBAAAAABBABAAAAABAAAB\r\nABABAABABBBABBAABBAA\r\nBAAABBBAAAABBBBBABAA\r\nAAABBABABAABBABAABAB\r\nABBABABABABAAABABABA\r\nBAABAAAAABBAABBBAAAB\r\nABAAABBABAABBBABAABA\r\nBAABBBBBABBBABBBABAB\r\nBABBABABBBBBBBBABAAA\r\nABAAABAAABAAABABABAA\r\nBAABBBBAABBAAAAAABBA\r\nABAABBABAAABBABABAAA\r\n', 'output': ['23\r\n1 10\r\n']}, {'input': '1 1\r\nC\r\n', 'output': ['1\r\n1 1\r\n']}, {'input': '2 2\r\nCC\r\nBB\r\n', 'output': ['2\r\n1 2\r\n']}, {'input': '3 3\r\nACA\r\nCCA\r\nACB\r\n', 'output': ['3\r\n1 3\r\n']}, {'input': '4 4\r\nACAC\r\nCBCC\r\nABBC\r\nCCAC\r\n', 'output': ['5\r\n1 4\r\n']}, {'input': '5 5\r\nBBCAB\r\nBCBAC\r\nCAAAB\r\nACBBA\r\nCAACB\r\n', 'output': ['3\r\n1 5\r\n']}, {'input': '14 16\r\nCBCCCABCBBBAAACC\r\nAABAACBACBCBACCA\r\nABBBABAACCACCCCC\r\nBBACACACCCCBBBAC\r\nBBCAABACBAACBCAA\r\nAAACCACBBCABABCB\r\nABCBCAAAAACBABBA\r\nAAABBBCCBAACBBCA\r\nBBAACBABBBCCBAAC\r\nBAABCCBAAABAACAC\r\nABBBBCBAACACCBCB\r\nBCABACBBBCAACACC\r\nACCCCABCCCBBCAAC\r\nBCBBCCCBCBCCACAA\r\n', 'output': ['15\r\n7 1\r\n']}, {'input': '16 16\r\nACABBCCBAABCCCCB\r\nAABCACCAAACACABB\r\nBCCCAABBAACBACAA\r\nBCACAABBBCAAAABA\r\nACCBABCCACABBCCC\r\nCCAAACACACBCABCA\r\nBCAACBBBCACBBCAB\r\nBABBCBBBCCCBAACC\r\nBBBBBABACBABBCBA\r\nABAACBACCACBBABA\r\nABAACBACCBCBCCBB\r\nBCACCCAABCBBCBCB\r\nBBBCCCBCCBCBACCA\r\nAABCBBBBACCACCBB\r\nBCABCCCBCBBBCBCC\r\nACCCCCCBBBAABACC\r\n', 'output': ['17\r\n4 2\r\n']}, {'input': '17 17\r\nBCBAAABAABCCCAAAC\r\nBBAABCABBAACCACBB\r\nABCCBAABBCCABBBAB\r\nAACCBBACCAAACCACA\r\nABBACBAAAABBABCAA\r\nACBACCCABAABBCABB\r\nCBCCCBCACBABCAAAA\r\nAAABACACABABCCCBC\r\nCABABBABBBABBBCAB\r\nBCBCBAAACCCACACBA\r\nBBACABACAAABCCBBC\r\nABAABBABCCAABBCCA\r\nAABBACBCBCCBAACBB\r\nBBABCBBCCCBCACBCB\r\nBABCBBCCABCABBAAA\r\nAABAABBBBAACAABCC\r\nBACCCBBCCABBBACBB\r\n', 'output': ['3\r\n1 17\r\n']}, {'input': '19 19\r\nACCACBCABACABCACCAA\r\nBCACAAAACCACCCCBCCB\r\nCBACBBCBCBCABCABACA\r\nAACCAABBBCAAABACAAC\r\nACACCCBBBACACCAAABA\r\nAACAABCACCBCACCABBA\r\nAABBCCABACCACABACAA\r\nACBCCACBACCACABCABC\r\nAACAABCAACCBBAACBCA\r\nAAACACBAABCBACCAAAB\r\nAABACABBABCACAACBCA\r\nBABAAABCACBABACBBBC\r\nBAABCAAABCAABBCCAAC\r\nBCABCCBCCBCBABCBCCA\r\nBACACBACBCABBCBCABB\r\nABCACCBBBBCBBCABAAC\r\nBBBBCCBCBACAACBCBCA\r\nAAABBBBCACCACCAAACC\r\nCCCCCBAABAAAACCCBBA\r\n', 'output': ['3\r\n1 19\r\n']}, {'input': '20 18\r\nAABCAACCBBCBABBBBB\r\nBBCBAACCBCAACBBCCB\r\nACCBABABACBBACBBAB\r\nACBBBCBAAACAAAAABB\r\nBCBABABAACCCABBBCC\r\nBAAAAAACACABBCCCAC\r\nCBACCBCBACACAAACBC\r\nCBACAACBCBCAACACCA\r\nCCCBACCBACACCCBCCB\r\nCACABBBBBBCCBACCBA\r\nCCBCACABCBACABBCCB\r\nAACACCCCCABAABCACC\r\nCBBACCBBCBCBBCCAAB\r\nCABBABACCABACAABAB\r\nBBBABBCBCBACBCCABA\r\nBCCAACBCBCAAAABACA\r\nAAABACBBCCCACACBAC\r\nBABAAAACCBACBACAAA\r\nAABBABCBBBACAACBAB\r\nBBABBAABACBAABCCBB\r\n', 'output': ['27\r\n4 2\r\n']}, {'input': '1 1\r\nZ\r\n', 'output': ['1\r\n1 1\r\n']}, {'input': '2 2\r\nML\r\nWQ\r\n', 'output': ['4\r\n1 1\r\n']}, {'input': '3 3\r\nBXP\r\nUJF\r\nAQT\r\n', 'output': ['4\r\n1 1\r\n']}, {'input': '4 3\r\nOKJ\r\nXTV\r\nDVW\r\nHMK\r\n', 'output': ['5\r\n2 1\r\n']}, {'input': '5 5\r\nDZEZF\r\nOHZZC\r\nCNDOX\r\nNVYDP\r\nUCIAX\r\n', 'output': ['3\r\n1 5\r\n']}, {'input': '6 6\r\nQLXBOE\r\nKEEYTR\r\nZLPMSP\r\nWOKAHN\r\nLYXBXU\r\nSZOEZV\r\n', 'output': ['14\r\n2 1\r\n']}, {'input': '6 7\r\nGYSGYUL\r\nKGTJUVI\r\nFNRHOND\r\nZGZAFYZ\r\nQVCRZCA\r\nJCCXKGV\r\n', 'output': ['7\r\n2 1\r\n']}, {'input': '8 8\r\nTNMIIMOP\r\nJOAXSHVN\r\nQYHMVXGM\r\nQOXAIUMI\r\nLAAXNKCH\r\nORWESZUV\r\nPMIXHLEA\r\nAENPGVYK\r\n', 'output': ['13\r\n1 4\r\n']}, {'input': '9 9\r\nIZHKRCRTM\r\nLQBOENMNQ\r\nYLNVFBFUY\r\nACTTYWABL\r\nYSEGWNQHC\r\nTZASWPPAG\r\nLLZTKFPMV\r\nGXBETPPPN\r\nUCPEFNJKN\r\n', 'output': ['8\r\n1 3\r\n']}, {'input': '9 10\r\nXHPCDAAFPZ\r\nJRZCDTQBYP\r\nZBTAMDPIFY\r\nXBKTMXNIWM\r\nDAIONPEBYF\r\nAFHBCBDTKB\r\nKRVEBSUXRM\r\nWGMEZTWDBX\r\nNOJUCDZPZY\r\n', 'output': ['10\r\n3 1\r\n']}, {'input': '12 13\r\nTHSGJEPTDFEIJ\r\nOWPJGXSXJRYGD\r\nVYENWXFWSOSMX\r\nFZDFXFPWEIYYV\r\nOEODFOGQWJEEU\r\nSQRNSBTAMLQRU\r\nLXGZERSWTJWQK\r\nLGRJJMDTZVZWJ\r\nDWVBTSZKFUAHT\r\nHSSZHXAWVWMHB\r\nJZOCNFUHTHQYV\r\nTUHDMTZAQVWDL\r\n', 'output': ['10\r\n3 1\r\n']}, {'input': '14 13\r\nBGBALYLHQYMFM\r\nRLFOZFDFMRFEN\r\nGDWROOMXUVBOW\r\nDPXWRDPCEFMRQ\r\nJOSEGKGMHGHFC\r\nJHXUBTPOZOYGJ\r\nFHUUMHWSQRNEP\r\nVGWYMTMWHWGIL\r\nVMWDTBDJGEVZI\r\nLEJSIHTQKYDXY\r\nOLUOIWECMZVAI\r\nVDXSGRPMCCJEM\r\nMYWMDDAQAPBSG\r\nXQWPFRAPVEOYO\r\n', 'output': ['6\r\n7 1\r\n']}, {'input': '14 15\r\nJFLSOQHVDRTCPWZ\r\nWSROLOOQOCWPJNX\r\nEEUZVBLQXBFQKNA\r\nQIGZDIMDXVCHJFJ\r\nUDJGIZWDBMMMBJR\r\nEWXAQHPRYBQOYDT\r\nUDEAPOBVZOXNVMK\r\nAYEVKFIKNRUVRQC\r\nNLTLJBXWMUQXAZD\r\nKOXESBBUYLMIDOI\r\nZOJWEOJFCYTILHE\r\nRQDNTBZZXPKNCEN\r\nSYGFASAQUSMYYRP\r\nUOYCFYUDACJDTAD\r\n', 'output': ['13\r\n1 5\r\n']}, {'input': '16 15\r\nPFUMRKDISIBBVYP\r\nMZKXWWSQXADAPEB\r\nVTBYXGWQYZTHBHY\r\nONGURZKWHZDKIDF\r\nGCMHQQNJJXHHPVU\r\nNLMUXXKZOFNMFTG\r\nANDDDPHEDVWVHLC\r\nOYGXUHIMYPNIXCT\r\nILCGDQZNCSTIILX\r\nZVSYMJBHAUEXZMY\r\nMYOKFPJKKJLKVWI\r\nUEMUOOAJSNTOLEN\r\nLKIROZUNWRZBMZP\r\nYYWCXLGHLZQVPOB\r\nFMHPKABCBAAYCFA\r\nNRGFEWPLKNORSZR\r\n', 'output': ['18\r\n1 3\r\n']}, {'input': '14 17\r\nXGFETCAWEBHYYDECE\r\nCGFEUQEYMLSVHNKJA\r\nZMGSXZJASBUPTHRFQ\r\nGQREDKHDBTZPGWHEO\r\nQGACDHZVBAOGLHHEL\r\nLKLKVFVDHSRQNEDXC\r\nVNREYHZDJHPJKHXDO\r\nKBOMZYHZEUOYUOXSQ\r\nFNQGOBVDBTMUJPAKU\r\nXFPGQQXBPELKWSXCJ\r\nABUKLBPTFOGUJFDEQ\r\nKXPJEZJQCHTENYSKY\r\nXXOKEXESEVLQMFDZG\r\nVPGUBSJLGBWZWAMFZ\r\n', 'output': ['6\r\n7 1\r\n']}, {'input': '16 17\r\nFFOYWWWJRUPVBGSSJ\r\nVPOMWQMWUWYMMDAPB\r\nARQUYXZTHVSQZHMVJ\r\nCJAGELECYEXSHEYTU\r\nXRSZPRCBQPJQACNWR\r\nJISALKDCKJUWWHMYH\r\nGMISALZMLGRRGALJA\r\nCWPYTQYBXKLBGWKNF\r\nMJJYWBIHJLARHFNWB\r\nKEREXXISTPANXGGJG\r\nLECEJLPAFOZHLRTJM\r\nHBOWFNSQFRRGEJFMJ\r\nVEGIRVEXACMJVKFYN\r\nSCGOPQKUHEDNIPIRE\r\nLENRPPYJBEVDTOPOY\r\nFHJOESUHLIJRFPVBK\r\n', 'output': ['8\r\n4 1\r\n']}, {'input': '18 19\r\nLEXQWPUXGOWSELHIQPY\r\nZUYPTUDHEEQVRWBCXBU\r\nZUPMYQQQFHGKZZDMLFM\r\nCASSUVIKQKCEALUDDFK\r\nFDBZOXULVGFARYPNAQY\r\nWEFLTZOSOAGAMBWNGVC\r\nEVAPNTSSIMKNBOAHFSC\r\nUHTWEBRCEUJSARNEWYI\r\nGXGSDCDUIWYQRZUPQBZ\r\nFMYJUOHENURMDINJGCN\r\nHIBATJCOGWWRQWTLXDH\r\nRDDXJNZHQGUWPNGIDRO\r\nAJGHDUCGGLPYYDYSFRS\r\nAZGBVLJYYZWSQGBFJVU\r\nQJJRSHZFOECHGRGALML\r\nJKDMLPREFTISSSAJKJN\r\nGRHGVYSVQLYKCIMBIKA\r\nMSHRBZJJLDHBCAWAJBN\r\n', 'output': ['10\r\n3 1\r\n']}, {'input': '20 18\r\nNLBILWYVJJLCACSMUA\r\nAAMAWVGEZDTWUUZNMM\r\nWWNOTPPFXJSWWSPPRB\r\nYUJXZSHHNFGKXIXEJN\r\nLTKNJOJALEQURSYVBI\r\nSVXHFTUYWTLBXWFDXD\r\nLQUEBPXELRNAXFIKFT\r\nZGZEPWGVLVNMQVRMJM\r\nWTMIPWRNQCWKZACSKQ\r\nYGUREEGHTVMICOCUHE\r\nUNIJGNPINIFWCIHGIQ\r\nIRGJEHFRUJOHIXRSLF\r\nDQVCPHUSKYEHFGWBPS\r\nJIIGNJKTRAAPRBOGMQ\r\nHFNGDLVBUVECUMQDMT\r\nGEGCSOPRXQAEMDQAYO\r\nOHSBTADOWBVKZINKXC\r\nIIPWCAZSNDFVBMTGMI\r\nOZZTLUOFRYDNTPIAVA\r\nTFBGPAMJPIWLEZOKXB\r\n', 'output': ['33\r\n1 3\r\n']}, {'input': '2 4\r\nABAA\r\nABBB\r\n', 'output': ['2\r\n1 4\r\n']}, {'input': '6 6\r\nCCABCA\r\nBCBCBC\r\nBAAAAA\r\nCBBCAA\r\nACBBCA\r\nCCAABA\r\n', 'output': ['10\r\n1 6\r\n']}, {'input': '16 4\r\nBAAC\r\nBACA\r\nACBC\r\nABCC\r\nCCAC\r\nBBCC\r\nCCAB\r\nABCC\r\nCBCA\r\nBCBC\r\nBCBC\r\nCBBB\r\nBBAA\r\nBACA\r\nABCB\r\nAABA\r\n', 'output': ['9\r\n2 4\r\n']}, {'input': '2 14\r\nAABACBACBCBBCB\r\nBACCBBBCBAABBC\r\n', 'output': ['4\r\n1 7\r\n']}, {'input': '4 8\r\nCACABCCA\r\nABCBAACA\r\nACABBBCC\r\nAACCBCBB\r\n', 'output': ['8\r\n1 4\r\n']}, {'input': '12 18\r\nCBBCAACABACCACABBC\r\nABCAACABAABCBCBCCC\r\nBCAACCCBBBABBACBBA\r\nACCBCBBBAABACCACCC\r\nCAABCCCACACCBACACC\r\nBBBCBCACCABCCBCBBB\r\nBAABBCACAAAAACCBCB\r\nBAABAABACBCABACBCA\r\nAABCBCCBCCABACCCAC\r\nCCBBBAACCCBCACCCBB\r\nCBABACBBBABCBACCCB\r\nAABACCCBCCACBCACCB\r\n', 'output': ['24\r\n4 2\r\n']}]


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;

public class C {

	static int k;

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt(), m = sc.nextInt();
		k = sc.nextInt();
		ArrayList<Integer>[] adjList = new ArrayList[n];
		for(int i = 0; i < n; ++i)
			adjList[i] = new ArrayList<>(1);
		while(m-->0)
		{
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
			adjList[u].add(v);
			adjList[v].add(u);
		}
		Comp[] comps = new Comp[n];
		int sz = 0;
		boolean[] vis = new boolean[n];
		for(int i = 0; i < n; ++i)
			if(!vis[i])
			{
				int s = 0;
				Queue<Integer> q =  new LinkedList<>();
				vis[i] = true;
				q.add(i);
				while(!q.isEmpty())
				{
					++s;
					int u = q.remove();
					for(int v: adjList[u])
						if(!vis[v])
						{
							vis[v] = true;
							q.add(v);
						}
				}
				comps[sz++] = new Comp(s);
			}
		Arrays.sort(comps, 0, sz);
		int idx = sz - 2, ans = 0, pIdx = sz - 1;
		PriorityQueue<Comp> cand = new PriorityQueue<>(new Selector());
		while(idx >= 0)
		{

			while(pIdx > idx && comps[pIdx].used == comps[pIdx].pt)
				cand.add(comps[pIdx--]);
			if(pIdx == idx)
			{
				++ans;
				Comp best = cand.remove();
				int used = best.used;
				best = new Comp(best.sz + comps[idx].sz);
				best.used = used;
				comps[idx] = best;
			}
			else
			{
				comps[pIdx].used++;
				comps[idx].used++;
			}
			idx--;
		}
		out.println(ans);
		out.close();
	}

	static class Selector implements Comparator<Comp>
	{
		public int compare(Comp a, Comp b)
		{
			return b.x - a.x;
		}
	}

	static class Comp implements Comparable<Comp>
	{
		int sz, pt, x, used;

		Comp(int a) { sz = a; pt = Math.min(sz, k); x = k - pt; }

		public int compareTo(Comp c) { return sz - c.sz; }
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }

		public boolean ready() throws IOException {return br.ready();}
	}
}

Vasya plays FreeDiv. In this game he manages a huge state, which has n cities and m two-way roads between them. Unfortunately, not from every city you can reach any other one moving along these roads. Therefore Vasya decided to divide the state into provinces so that in every province, one could reach from every city all the cities of the province, but there are no roads between provinces. Unlike other turn-based strategies, in FreeDiv a player has the opportunity to build tunnels between cities. The tunnels are two-way roads along which one can move armies undetected by the enemy. However, no more than one tunnel can be connected to each city. As for Vasya, he wants to build a network of tunnels so that any pair of cities in his state were reachable by some path consisting of roads and a tunnels. But at that no more than k tunnels are connected to each province (otherwise, the province will be difficult to keep in case other provinces are captured by enemy armies).Vasya discovered that maybe he will not be able to build such a network for the current condition of the state. Maybe he'll have first to build several roads between cities in different provinces to merge the provinces. Your task is to determine the minimum number of roads Vasya needs to build so that it was possible to build the required network of tunnels in the resulting state.

The first line contains three integers n, m and k (1 ≤ n, k ≤ 106, 0 ≤ m ≤ 106). Each of the next m lines contains two integers. They are the numbers of cities connected by a corresponding road. No road connects city to itself and there is at most one road between each pair of cities.

Print a single number, the minimum number of additional roads.

NoteIn the first example only one province exists, so it is not necessary to build any tunnels or roads.In the second example two provinces exist. It is possible to merge the provinces by building a tunnel between cities 1 and 3.In the third example at least one additional road is necessary. For example it is possible to build additional road between cities 1 and 2 and build two tunnels between cities 1 and 3, 2 and 4 after that.

import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Collections;
import java.io.InputStream;

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

class TaskD {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        DisjointSet dsu = new DisjointSet(n);
        int[] size = new int[n];
        Arrays.fill(size, 1);
        while (m-- > 0) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            int newSize = size[dsu.findSet(a)] + size[dsu.findSet(b)];
            if (dsu.union(a, b)) {
                int newRep = dsu.findSet(a);
                size[newRep] = newSize;
            }
        }
        List<Integer> componentSizes = new LinkedList<Integer>();
        boolean[] u = new boolean[n];
        for (int i = 0; i < n; ++i) {
            int rep = dsu.findSet(i);
            if (!u[rep]) {
                u[rep] = true;
                componentSizes.add(Math.min(size[rep], k));
            }
        }
        if (k == 1) {
            out.println(Math.max(0, componentSizes.size() - 2));
            return;
        }

        Collections.sort(componentSizes);
        int singleComponent = 0;
        while (!componentSizes.isEmpty() && componentSizes.get(0) == 1) {
            ++singleComponent;
            componentSizes.remove(0);
        }
        int freeLinks = 0;
        int edges = 0;
        for (int sz : componentSizes) {
            if (edges < 2) {
                freeLinks += sz - 1;
            } else {
                freeLinks += sz - 2;
            }
            ++edges;
        }
        if (singleComponent == 0) {
            out.println(0);
            return;
        }
        if (edges == 0) {
            singleComponent = (singleComponent + 1) / 2;
            out.println(singleComponent-1);
            return;
        }
        if (edges == 1) {
            ++freeLinks;
        }
        if (singleComponent <= freeLinks) {
            out.println(0);
        } else {
            singleComponent -= freeLinks;
            singleComponent = (singleComponent + 1) / 2;
            out.println(singleComponent);
        }
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class DisjointSet {
    int[] parent;
    int[] rank;

    public DisjointSet(int size) {
        parent = new int[size];
        rank = new int[size];
        for (int i = 0; i < size; ++i) {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    public int findSet(int x) {
        if (parent[x] != x) {
            parent[x] = findSet(parent[x]);
        }
        return parent[x];
    }

    public boolean union(int x, int y) {
        x = findSet(x);
        y = findSet(y);
        if (x != y) {
            if (rank[x] < rank[y]) {
                parent[x] = y;
            } else {
                parent[y] = x;
                if (rank[x] == rank[y]) {
                    ++rank[x];
                }
            }
            return true;
        }
        return false;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class ConvexHull {

    static class Point{
        int x;
        int y;
        Point(int x, int y){
            this.x = x;
            this.y = y;
        }
    }

    static int cross(Point a, Point b, Point c){
       return (b.x - a.x) * (c.y - a.y) - (b.y - a.y)*(c.x - a.x);
    }

    static boolean isItOut(Point a, Point b, Point c, boolean upper){
        if(a == null || b == null) {
            return true;
        }
        if(upper && (a == b && a.y < c.y || cross(a,b,c) > 0)){
            return true;
        }
        if(!upper && (a == b && a.y > c.y || cross(a,b,c) < 0)){
            return true;
        }

        return false;
    }

    static void removePoint(TreeSet<Point> t, Point p, boolean right, boolean upper){
        Point a = right ? t.ceiling(p) : t.floor(p);
        if(a == null){
            return;
        }
        if(a.x == p.x){
            t.remove(a);
            a = right ? t.ceiling(p) : t.floor(p);
        }
        if(a == null){
            return;
        }
        Point b = right ? t.higher(a) : t.lower(a);
        int sign = upper ? 1 : -1;
        sign = right ? sign * 1 : sign * -1;
        while(b != null && cross(p, a, b) * sign >= 0){

            t.remove(a);
            a = b;
            b = right ? t.higher(a) : t.lower(a);

        }
    }

    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        //upper hull
        TreeSet<Point> upper = new TreeSet<>((a,b) -> a.x - b.x);
        //lower hull
        TreeSet<Point> lower = new TreeSet<>((a,b) -> a.x - b.x);

        while(q > 0){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int t = Integer.parseInt(st.nextToken());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            Point p = new Point(x,y);
            Point ul = upper.floor(p);
            Point ur = upper.ceiling(p);
            Point ll = lower.floor(p);
            Point lr = lower.ceiling(p);

            boolean outupper = isItOut(ul, ur, p, true);
            boolean outlower = isItOut(ll, lr, p, false);

            if(t == 1){
                //add to convex hull
                if(outupper){
                    removePoint(upper, p, true, true);
                    removePoint(upper, p, false, true);
                    upper.add(p);
                }
                if(outlower){
                    removePoint(lower, p, true, false);
                    removePoint(lower, p, false, false);
                    lower.add(p);
                }

            }else{
                //see if in convex hull
                //is it right or left?
                System.out.println(outupper || outlower ? "NO" : "YES");
                //above top curve

                //below bottom curve

            }
            //Point[] up = upper.toArray();
            //System.out.printf("UPPER:  ");
            //for(int i = 0; i < up.length; i ++){
            //    System.out.printf("%d %d   ", up[i].x, up[i].y);
            //}

            //Object[] low = lower.toArray();
            //System.out.printf("\nLOWER:  ");
            //for(int i = 0; i < low.length; i ++){
            //    System.out.printf("%d %d   ", low[i].x, low[i].y);
            //}
            //System.out.println();

            q--;
        }

    }

}

Once a walrus professor Plato asked his programming students to perform the following practical task. The students had to implement such a data structure that would support a convex hull on some set of points S. The input to the program had q queries of two types: 1. Add a point with coordinates (x, y) into the set S. Note that in this case the convex hull of S could have changed, and could have remained the same. 2. Say whether a point with coordinates (x, y) belongs to an area limited by the convex hull, including the border. All the students coped with the task. What about you?

The first line contains an integer q (4 ≤ q ≤ 105).  Then follow q lines in the following way: "t x y", where t is the query type (1 or 2), and (x, y) are the coordinates of the point ( - 106 ≤ x, y ≤ 106, x and y are integers).  There is at least one query of type 2. It is guaranteed that the three queries of the first type follow first and the points given in the queries form a non-degenerative triangle. Also all the points added in S are distinct.

For each query of the second type print one string containing "YES", if the point lies inside the convex hull or on its border. Otherwise, print "NO".

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class ConvexHull {

    static class Point{
        int x;
        int y;
        Point(int x, int y){
            this.x = x;
            this.y = y;
        }
    }

    static long cross(Point a, Point b, Point c){
       return (long) (b.x - a.x) * (c.y - a.y) - (long) (b.y - a.y)*(c.x - a.x);
    }

    static boolean isItOut(Point a, Point b, Point c, boolean upper){
        if(a == null || b == null) {
            return true;
        }
        if(upper && (a == b && a.y < c.y || cross(a,b,c) > 0)){
            return true;
        }
        if(!upper && (a == b && a.y > c.y || cross(a,b,c) < 0)){
            return true;
        }
        return false;
    }

    static void removePoint(TreeSet<Point> t, Point p, boolean right, boolean upper){
        Point a = right ? t.ceiling(p) : t.floor(p);
        if(a == null){
            return;
        }
        if(a.x == p.x){
            t.remove(a);
            a = right ? t.ceiling(p) : t.floor(p);
        }
        if(a == null){
            return;
        }
        Point b = right ? t.higher(a) : t.lower(a);
        int sign = upper ? 1 : -1;
        sign = right ? sign * 1 : sign * -1;
        while(b != null && cross(p, a, b) * sign >= 0){

            t.remove(a);
            a = b;
            b = right ? t.higher(a) : t.lower(a);

        }
    }

    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        //upper hull
        TreeSet<Point> upper = new TreeSet<>((a,b) -> a.x - b.x);
        //lower hull
        TreeSet<Point> lower = new TreeSet<>((a,b) -> a.x - b.x);

        while(q > 0){
            StringTokenizer st = new StringTokenizer(br.readLine());
            int t = Integer.parseInt(st.nextToken());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            Point p = new Point(x,y);
            Point ul = upper.floor(p);
            Point ur = upper.ceiling(p);
            Point ll = lower.floor(p);
            Point lr = lower.ceiling(p);

            boolean outupper = isItOut(ul, ur, p, true);
            boolean outlower = isItOut(ll, lr, p, false);

            if(t == 1){
                //add to convex hull
                if(outupper){
                    removePoint(upper, p, true, true);
                    removePoint(upper, p, false, true);
                    upper.add(p);
                }
                if(outlower){
                    removePoint(lower, p, true, false);
                    removePoint(lower, p, false, false);
                    lower.add(p);
                }

            }else{
                //see if in convex hull
                //is it right or left?
                System.out.println(outupper || outlower ? "NO" : "YES");
                //above top curve

                //below bottom curve

            }
            //Point[] up = upper.toArray();
            //System.out.printf("UPPER:  ");
            //for(int i = 0; i < up.length; i ++){
            //    System.out.printf("%d %d   ", up[i].x, up[i].y);
            //}

            //Object[] low = lower.toArray();
            //System.out.printf("\nLOWER:  ");
            //for(int i = 0; i < low.length; i ++){
            //    System.out.printf("%d %d   ", low[i].x, low[i].y);
            //}
            //System.out.println();

            q--;
        }

    }

}


import java.io.*;
import java.util.*;

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);
        TaskD solver = new TaskD();
        solver.solve(in, out);
        out.close();
    }
}

class TaskD {

    public void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int x = in.nextInt();

        int firstTour[] = new int[n];
        for (int i = 0; i < n; i++) {
            firstTour[i] = in.nextInt();
        }
        int secondTour[] = new int[n];
        for (int i = 0; i < n; i++) {
            secondTour[i] = in.nextInt();
        }
        int worstPlace = 0;
        Arrays.sort(firstTour);
        Arrays.sort(secondTour);

        int i = 0;
        int j = n-1;
        while(i < n && j >= 0) {
            if(firstTour[i] + secondTour[j] >= x) {
                i++;
                j--;
                worstPlace++;
            } else {
                i++;
            }
        }

        out.printLine("1 " + worstPlace);
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if (line == null) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }

}

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 print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

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

}

A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.Help Vasya's teacher, find two numbers — the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.

The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned. The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour. The third line contains n space-separated integers: b1, b2, ..., bn (0 ≤ bi ≤ 105) — the participants' points in the second tour. The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad — there are two integers i, j (1 ≤ i, j ≤ n) such, that ai + bj ≥ x.

Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.

NoteIn the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that — {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.In the worst case scenario Vasya can get the fifth place if the table looks like that — {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.

import java.io.*;
import java.util.*;

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);
        TaskD solver = new TaskD();
        solver.solve(in, out);
        out.close();
    }
}

class TaskD {

    public void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int x = in.nextInt();

        List<Integer> firstTour = new ArrayList<>(n);
        List<Integer> secondTour = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            firstTour.add(in.nextInt());
        }
        for (int i = 0; i < n; i++) {
            secondTour.add(in.nextInt());
        }
        int worstPlace = 0;
        firstTour.sort(Comparator.<Integer>naturalOrder());
        secondTour.sort(Comparator.<Integer>naturalOrder());
        int i = 0;
        int j = n-1;
        while(i < n && j >= 0) {
            if(firstTour.get(i) + secondTour.get(j) >= x) {
                i++;
                j--;
                worstPlace++;
            } else {
                i++;
            }
        }

        out.printLine("1 " + worstPlace);
    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if (line == null) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }

}

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 print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

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

}


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Solution {

	private static Scanner sc;

	public static void main(String[] args) {

		sc = new Scanner(System.in);

		int n = sc.nextInt();
		double[][] A = new double [n][2];
		Map<Double, Integer> M1 = new HashMap<Double, Integer>();
		Map<Double, Set<Double>> M2 = new HashMap<Double, Set<Double>>();

		for (int i = 0; i < n ; ++i) {
			A[i][0] = sc.nextDouble();
			A[i][1] = sc.nextDouble();
		}

		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {

				double m;

				if (A[i][0] - A[j][0] == 0) {
					m = 2000000000;
				}
				else {
					m = (A[i][1] - A[j][1]) / ( A[i][0] - A[j][0]);
				}

				if (!M1.containsKey(m)) {
					M1.put(m, 0);
					M2.put(m, new HashSet<Double>());
				}

				int cnt = M1.get(m);

				M1.put(m, cnt + 1);

				if (m == 2000000000) {
					M2.get(m).add(A[i][0]);
				} else {
					M2.get(m).add(A[i][1] - m * A[i][0]);
				}
			}
		}

		long tot = 0;
		long cnt = 0;

		for (double m : M2.keySet()) {
			tot += M2.get(m).size();
		}

		for (double m : M2.keySet()) {
			cnt += (tot - M2.get(m).size()) * M2.get(m).size();
		}

		System.out.println(cnt / 2);

		sc.close();
	}
}

This problem is same as the next one, but has smaller constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $$$(x_i, y_i)$$$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of electric poles. Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \le x_i, y_i \le 10^4$$$) — the coordinates of the poles. It is guaranteed that all of these $$$n$$$ points are distinct.

Print a single integer — the number of pairs of wires that are intersecting.

NoteIn the first example:  In the second example:  Note that the three poles $$$(0, 0)$$$, $$$(0, 2)$$$ and $$$(0, 4)$$$ are connected by a single wire.In the third example:

import java.util.*;
import java.io.*;
import java.lang.*;

public final class Solution {

    private final static boolean USE_FILE_IO = false;

    Reader reader;
    Writer writer;

    Solution(Reader reader, Writer writer) {
        this.reader = reader;
        this.writer = writer;
    }

    long solve() throws java.lang.Exception {
        int n = reader.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i=0; i<n; i++) {
            x[i] = reader.nextInt();
            y[i] = reader.nextInt();
        }
        long ans = 0;
        HashMap<Long, Integer> slopes = new HashMap<Long, Integer>();
        HashSet<Line> lines = new HashSet<Line>();
        for (int i=0; i<n-1; i++) {
            for (int j=i+1; j<n; j++) {
                Line line = new Line(x[i], y[i], x[j], y[j]);
                if (lines.add(line)) {
                    ans += (long)lines.size() - 1;
                    long slope = line.getSlope();
                    int count = slopes.getOrDefault(slope, 0);
                    ans -= (long)count;
                    slopes.put(slope, count + 1);
                }
            }
        }
        return ans;
    }

    class Line {
        int a, b, c;
        Line(int x1, int y1, int x2, int y2) {
            a = y2 - y1;
            b = x1 - x2;
            c = y1 * x2 - y2 * x1;
            if (a < 0 || (a==0 && b < 0)) {
                a = -a;
                b = -b;
                c = -c;
            }
            int gcd = gcd(gcd(Math.abs(a), Math.abs(b)), Math.abs(c));
            a /= gcd;
            b /= gcd;
            c /= gcd;
        }

        long getSlope() {
            return (long)a * 100000L + (long)b;
        }

        @Override
        public int hashCode() {
            return a ^ b ^ c;
        }

        @Override
        public boolean equals(Object o) {
            if (o == this) return true;
            if (o.getClass() != Line.class) return false;
            Line other = (Line) o;
            return other.a == this.a && other.b == this.b && other.c == this.c;
        }
    }

    static int gcd(int a, int b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }

    public static void main(String[] args) throws java.lang.Exception {
        Reader reader = null;
        Writer writer = null;
        try {
            if (USE_FILE_IO) {
                reader = new Reader(new FileInputStream("input.txt"));
                writer = new Writer(new FileOutputStream("output.txt"));
            } else {
                reader = new Reader(System.in);
                writer = new Writer(System.out);
            }
            writer.writeLine(new Solution(reader, writer).solve());
        } finally {
            if (reader != null)
                reader.close();
            if (writer != null)
                writer.close();
        }
    }

    static class Writer {
        BufferedWriter bw;

        public Writer(OutputStream out) {
            bw = new BufferedWriter(new OutputStreamWriter(out));
        }

        void write(String s) throws java.lang.Exception {
            bw.write(s);
        }

        void write(int x) throws java.lang.Exception {
            write(String.valueOf(x));
        }

        void write(long x) throws java.lang.Exception {
            write(String.valueOf(x));
        }

        void write(char c) throws java.lang.Exception {
            bw.write(c);
        }

        void newLine() throws java.lang.Exception {
            bw.newLine();
        }

        void writeLine(String s) throws java.lang.Exception {
            write(s);
            newLine();
        }

        void writeLine(int n) throws java.lang.Exception {
            writeLine(String.valueOf(n));
        }

        void writeLine(long n) throws java.lang.Exception {
            writeLine(String.valueOf(n));
        }

        void writeLine() throws java.lang.Exception {
            writeLine("");
        }

        void close() throws java.lang.Exception {
            bw.flush();
            bw.close();
        }
    }

    static class Reader {
        BufferedReader br;
        StringTokenizer st;

        public Reader(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String[] nextTokens(int n) {
            String[] a = new String[n];
            for (int i=0; i<n; i++) {
                a[i] = nextToken();
            }
            return a;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        int[] nextInts(int n) {
            int[] a = new int[n];
            for (int i=0; i<n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        long[] nextLongs(int n) {
            long[] a = new long[n];
            for (int i=0; i<n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        void close() throws java.lang.Exception {
            br.close();
        }
    }
}


/**
 * ******* Created on 19/9/19 3:33 AM*******
 */

import java.io.*;
import java.util.*;

public class B7 {
    public static void main(String[] args) throws IOException {
        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            int t = input.nextInt();
            int m = input.nextInt();
            int[] arr = new int[m];
            for(int i=0;i<m;i++) {
                arr[i]=0;
            }
            int id =0;
            while(t-- >0){
                String s = input.next();
                if(s.equals("defragment")){
                    int i=0, j=0;
                    while(arr[j]!=0 && j<m)j++;
                    while(arr[i]==0 && i<m)i++;
                    for(;i<m;i++){
                        if(arr[i]!=0 && i>j){
                            arr[j]= arr[i];
                            arr[i]=0;
                            j++;
                        }
                        while(arr[j]!=0 && j<m) j++;
                    }
                }else if(s.equals("alloc")){
                    int size = input.nextInt();
                    int cnt1 =0, pos =-1;
                    for(int i=0;i<m;i++){
                        if(arr[i]==0)cnt1++;
                        else cnt1 =0;
                        if(cnt1 ==size){
                            id++;
                            pos =i;
                            break;
                        }
                    }
                    if(pos ==-1){
                        System.out.println("NULL");
                    }else{
                        System.out.println(id);
                        for(int i=pos, k=0;k<size;k++,i--)
                            arr[i]=id;
                    }
                }else{
                    int ids = input.nextInt();
                    boolean flag =false;
                    for(int i=0;i<m;i++){
                        if(arr[i]==ids){
                            flag =true;
                            arr[i]=0;
                        }
                    }
                    if(!flag){
                        System.out.println("ILLEGAL_ERASE_ARGUMENT");
                    }
                }
            }
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}

There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:   alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;  erase x — to erase the block with the identifier x;  defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

The first line of the input data contains two positive integers t and m (1 ≤ t ≤ 100;1 ≤ m ≤ 100), where t — the amount of operations given to the memory manager for processing, and m — the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1 ≤ n ≤ 100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.

Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.

6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6

/**
 * ******* Created on 19/9/19 3:33 AM*******
 */

import java.io.*;
import java.util.*;

public class B7 {
    public static void main(String[] args) throws IOException {
        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            int t = input.nextInt();
            int m = input.nextInt();
            int[] arr = new int[m];
            for(int i=0;i<m;i++) {
                arr[i]=0;
            }
            int id =0;
            while(t-- >0){
                String s = input.next();
                if(s.equals("defragment")){
                    for(int i=0, j=0;i<m;i++){
                        if(arr[j]!=0)j++;
                        if(arr[i]!=0 && j <i){
                            arr[j]= arr[i];
                            arr[i]=0;
                            j++;
                        }
                    }
                }else if(s.equals("alloc")){
                    int size = input.nextInt();
                    int cnt1 =0, pos =-1;
                    for(int i=0;i<m;i++){
                        if(arr[i]==0)cnt1++;
                        else cnt1 =0;
                        if(cnt1 ==size){
                            id++;
                            pos =i;
                            break;
                        }
                    }
                    if(pos ==-1){
                        System.out.println("NULL");
                    }else{
                        System.out.println(id);
                        for(int i=pos, k=0;k<size;k++,i--)
                            arr[i]=id;
                    }
                }else{
                    int ids = input.nextInt();
                    boolean flag =false;
                    for(int i=0;i<m;i++){
                        if(arr[i]==ids){
                            flag =true;
                            arr[i]=0;
                        }
                    }
                    if(!flag || ids <=0){
                        System.out.println("ILLEGAL_ERASE_ARGUMENT");
                    }
                }
            }
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

        default int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        default long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        default double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}

[{'input': '6 10\r\nalloc 5\r\nalloc 3\r\nerase 1\r\nalloc 6\r\ndefragment\r\nalloc 6\r\n', 'output': ['1\r\n2\r\nNULL\r\n3\r\n']}, {'input': '6 1\r\ndefragment\r\nalloc 10\r\nalloc 1\r\nerase -1\r\nerase 1\r\nerase 1\r\n', 'output': ['NULL\r\n1\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '14 100\r\nalloc 99\r\nalloc 1\r\nalloc 1\r\nerase 2\r\nalloc 1\r\nerase 4\r\nerase 1\r\nalloc 100\r\nalloc 1\r\nalloc 99\r\ndefragment\r\nerase 4\r\nalloc 100\r\nalloc 99\r\n', 'output': ['1\r\n2\r\nNULL\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n4\r\nNULL\r\nNULL\r\nNULL\r\n']}, {'input': '26 25\r\ndefragment\r\nerase 1\r\nerase -1560200883\r\nalloc 44\r\ndefragment\r\nalloc 75\r\nalloc 22\r\ndefragment\r\nerase 4\r\ndefragment\r\nalloc 57\r\nalloc 53\r\nerase 4\r\nerase -1639632026\r\nerase -2121605039\r\nerase 3\r\nalloc 51\r\nalloc 65\r\ndefragment\r\nerase 2\r\nerase 4\r\nalloc 52\r\nerase 3\r\ndefragment\r\nerase -1842529282\r\nerase 3\r\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n1\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '22 9\r\nerase 1\r\nalloc 6\r\nalloc 65\r\nerase 1\r\nalloc 87\r\nerase -1638927047\r\nalloc 5\r\nerase 2\r\nalloc 70\r\ndefragment\r\nalloc 20\r\nalloc 48\r\nerase -69401977\r\nalloc 20\r\ndefragment\r\nerase 7\r\ndefragment\r\nerase 9\r\nerase 7\r\nerase 4\r\ndefragment\r\nalloc 66\r\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': '12 40\r\nerase 1\r\nalloc 21\r\nalloc 5\r\nalloc 7\r\ndefragment\r\ndefragment\r\nerase 2\r\nalloc 83\r\nerase 4\r\ndefragment\r\nalloc 59\r\ndefragment\r\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\n2\r\n3\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': '38 18\r\nalloc 72\r\nerase 2\r\nalloc 50\r\ndefragment\r\nerase 3\r\ndefragment\r\nalloc 43\r\nalloc 41\r\ndefragment\r\ndefragment\r\nalloc 26\r\nalloc 46\r\nalloc 16\r\nalloc 15\r\ndefragment\r\ndefragment\r\nalloc 95\r\nerase 7\r\nerase 7\r\nerase 5\r\nerase 2\r\nerase 9\r\nerase 7\r\nalloc 43\r\ndefragment\r\nerase 7\r\ndefragment\r\nalloc 48\r\nalloc 77\r\nerase 10\r\nerase 11\r\nalloc 16\r\nalloc 84\r\nerase 1\r\ndefragment\r\nalloc 86\r\ndefragment\r\nerase 13\r\n', 'output': ['NULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nNULL\r\n1\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '37 74\r\nalloc 11\r\ndefragment\r\nerase 1\r\ndefragment\r\nerase 2\r\ndefragment\r\nalloc 90\r\nerase 3\r\nerase 2\r\nerase 3\r\nerase 1\r\nerase 1\r\nalloc 38\r\nalloc 19\r\nerase 1\r\nerase 3\r\ndefragment\r\nalloc 93\r\nerase 5\r\nerase 4\r\nalloc 66\r\nalloc 71\r\nerase 5\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\nerase 7\r\nalloc 47\r\nerase -95616683\r\nerase 2\r\nalloc 28\r\nalloc 32\r\nerase 11\r\nalloc 50\r\ndefragment\r\ndefragment\r\n', 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n4\r\n5\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': '16 49\r\nerase -751005193\r\ndefragment\r\nalloc 37\r\nalloc 82\r\nerase 3\r\nerase 1\r\nalloc 80\r\nalloc 51\r\ndefragment\r\nalloc 74\r\nerase 1\r\nalloc 91\r\ndefragment\r\ndefragment\r\nalloc 98\r\ndefragment\r\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': '42 98\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 5\r\nalloc 66\r\ndefragment\r\nerase 3\r\nalloc 53\r\ndefragment\r\nerase 4\r\nerase 2\r\nalloc 70\r\nerase 3\r\ndefragment\r\ndefragment\r\nerase 2\r\nerase 3\r\nerase -1327931832\r\nalloc 93\r\nalloc 64\r\nerase 7\r\nerase 6\r\nerase 3\r\nalloc 61\r\nalloc 12\r\nalloc 65\r\nerase 2\r\nalloc 46\r\nerase 11\r\nerase 9\r\nerase 9\r\nerase 6\r\nalloc 2\r\nalloc 78\r\ndefragment\r\nerase 13\r\nerase 6\r\nerase 10\r\nalloc 53\r\nalloc 46\r\n', 'output': ['1\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n4\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': '19 46\r\nalloc 21\r\nerase 2\r\nerase 1\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nalloc 40\r\nerase 1\r\ndefragment\r\ndefragment\r\nalloc 68\r\nerase -388966015\r\nalloc 85\r\nalloc 53\r\nerase 4\r\ndefragment\r\nalloc 49\r\nalloc 88\r\n', 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\n']}, {'input': '44 46\r\nalloc 28\r\nalloc 36\r\ndefragment\r\nerase -937404236\r\nalloc 71\r\ndefragment\r\nalloc 81\r\nalloc 51\r\nerase 3\r\ndefragment\r\nalloc 48\r\nerase 1\r\ndefragment\r\nalloc 36\r\ndefragment\r\ndefragment\r\nerase 1\r\ndefragment\r\ndefragment\r\nerase -1173350787\r\nalloc 94\r\nerase 5\r\ndefragment\r\nerase 9\r\nalloc 98\r\nerase 7\r\ndefragment\r\nerase 5\r\nerase 1\r\ndefragment\r\nerase 2\r\ndefragment\r\nerase 4\r\ndefragment\r\nerase 9\r\nalloc 8\r\ndefragment\r\nerase 9\r\ndefragment\r\ndefragment\r\ndefragment\r\nerase 1\r\nalloc 70\r\nerase 9\r\n', 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nNULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '26 25\r\nalloc 25\r\nerase 1\r\nalloc 24\r\nerase 2\r\nalloc 23\r\nerase 3\r\nalloc 24\r\nerase 4\r\nalloc 24\r\nerase 5\r\nalloc 21\r\nerase 6\r\nalloc 24\r\nerase 7\r\nalloc 25\r\nerase 8\r\nalloc 25\r\nerase 9\r\nalloc 24\r\nerase 10\r\nalloc 25\r\nerase 11\r\nalloc 25\r\nerase 12\r\nalloc 25\r\nerase 13\r\n', 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n']}, {'input': '22 9\r\nalloc 9\r\nerase 1\r\nalloc 9\r\nerase 2\r\nalloc 9\r\nerase 3\r\nalloc 9\r\nerase 4\r\nalloc 9\r\nerase 5\r\nalloc 9\r\nerase 6\r\nalloc 9\r\nerase 7\r\nalloc 9\r\nerase 8\r\nalloc 9\r\nerase 9\r\nalloc 9\r\nerase 10\r\nalloc 9\r\nerase 11\r\n', 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n']}, {'input': '7 6\r\nalloc 1\r\nalloc 2\r\nalloc 3\r\nerase 1\r\ndefragment\r\nerase 3\r\nalloc 4\r\n', 'output': ['1\r\n2\r\n3\r\n4\r\n']}, {'input': '3 1\r\nerase -1\r\nerase 0\r\nerase -2147483648\r\n', 'output': ['ILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '7 100\r\nalloc 100\r\nerase 2147483647\r\nerase 1\r\nalloc 50\r\nalloc 50\r\nerase 3\r\nerase -2147483648\r\n', 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\n']}, {'input': '12 10\r\nalloc 6\r\nalloc 2\r\nerase 1\r\nalloc 4\r\nalloc 2\r\nerase 3\r\nalloc 2\r\nalloc 3\r\nalloc 1\r\nalloc 1\r\nalloc 1\r\nalloc 1\r\n', 'output': ['1\r\n2\r\n3\r\n4\r\n5\r\nNULL\r\n6\r\n7\r\n8\r\n9\r\n']}, {'input': '8 50\r\nalloc 51\r\ndefragment\r\nalloc 100\r\ndefragment\r\nerase 1\r\nalloc 50\r\ndefragment\r\nalloc 50\r\n', 'output': ['NULL\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n1\r\nNULL\r\n']}, {'input': '10 10\r\nalloc 10\r\nerase -1\r\nerase 1\r\nalloc 5\r\nerase -1\r\nalloc 5\r\nerase 0\r\nalloc 5\r\nerase 0\r\nalloc 5\r\n', 'output': ['1\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\nILLEGAL_ERASE_ARGUMENT\r\n3\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\nNULL\r\n']}, {'input': '16 10\r\nalloc 10\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 10\r\nerase 1\r\nerase 2\r\nalloc 6\r\ndefragment\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nerase 3\r\ndefragment\r\nalloc 6\r\n', 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\nNULL\r\n']}, {'input': '16 10\r\nalloc 10\r\ndefragment\r\ndefragment\r\ndefragment\r\nalloc 10\r\nerase 1\r\nerase 2\r\nalloc 6\r\ndefragment\r\ndefragment\r\nalloc 4\r\ndefragment\r\ndefragment\r\nerase 2\r\ndefragment\r\nalloc 6\r\n', 'output': ['1\r\nNULL\r\nILLEGAL_ERASE_ARGUMENT\r\n2\r\n3\r\n4\r\n']}]