import static java.lang.System.exit;

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

public class TestsGen {
	static final Random rand = new Random(345435L);

	static class Sentinel {
		int x;
		int y;
		int dir;

		public Sentinel(int x, int y, int dir) {
			this.x = x;
			this.y = y;
			this.dir = dir;
		}

		@Override
		public String toString() {
			return x + " " + y + " " + toChar(dir);
		}

		static char toChar(int dir) {
			return "NESW".charAt(dir);
		}

	}

	static int curTest = 0;

	static void printTest(Sentinel[] s) {
		System.err.println("Generating test #" + (++curTest));
		try {
			PrintWriter out = new PrintWriter("" + curTest / 10 + curTest % 10);
			out.println(s.length);
			for (Sentinel e : s) {
				out.println(e);
			}
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(213);
		}
	}

	static final int MAXN = 50000;
	static final int MAXX = 1000000000;

	public static void main(String[] args) {
		printTest(new Sentinel[] { new Sentinel(0, 0, 3), new Sentinel(1, 1, 0)});
		printTest(new Sentinel[] { new Sentinel(0, 0, 1),
				new Sentinel(1, 0, 0), new Sentinel(1, 1, 3),
				new Sentinel(0, 1, 2) });
		printTest(new Sentinel[] { new Sentinel(0, 0, 0) });
		printTest(maxAnswerTestV());
		printTest(maxAnswerTestH());
		printTest(maxRandomTest());
		printTest(maxRandomTest());
		printTest(maxRandomTest());
		for (int i = 0; i < 20; i++) {
			printTest(minRandomTest());
		}
		for (int i = 0; i < 4; i++) {
			printTest(oneLineRandom1());
		}
		for (int i = 0; i < 4; i++) {
			printTest(oneLineRandom2());
		}
		for (int i = 0; i < 20; i++) {
			printTest(genRandomTest());
		}
	}

	static Sentinel[] oneLineRandom2() {
		int dif = random(-MAXX / 2, MAXX / 2 + 1);
		int n = random(1, MAXN + 1);
		Set<Integer> set = new HashSet<Integer>();
		Sentinel[] ret = new Sentinel[n];
		for (int i = 0; i < n; i++) {
			int x;
			do {
				x = random(-MAXX / 2, MAXX / 2 + 1);
			} while (!set.add(x));
			ret[i] = new Sentinel(x, dif + x, random(0, 4));
		}
		return ret;
	}

	static Sentinel[] oneLineRandom1() {
		int sum = random(-MAXX / 2, MAXX / 2 + 1);
		int n = random(1, MAXN + 1);
		Set<Integer> set = new HashSet<Integer>();
		Sentinel[] ret = new Sentinel[n];
		for (int i = 0; i < n; i++) {
			int x;
			do {
				x = random(-MAXX / 2, MAXX / 2 + 1);
			} while (!set.add(x));
			ret[i] = new Sentinel(x, sum - x, random(0, 4));
		}
		return ret;
	}

	static Sentinel[] minRandomTest() {
		int n = random(2, 10);
		Sentinel[] ret = new Sentinel[n];
		Set<Pair> set = new HashSet<Pair>();
		for (int i = 0; i < n; i++) {
			int x, y;
			do {
				x = random(-MAXX, MAXX + 1);
				y = random(-MAXX, MAXX + 1);
			} while (!set.add(new Pair(x, y)));
			ret[i] = new Sentinel(x, y, random(0, 4));
		}
		return ret;
	}

	static Sentinel[] maxRandomTest() {
		Sentinel[] ret = new Sentinel[MAXN];
		Set<Pair> set = new HashSet<Pair>();
		for (int i = 0; i < MAXN; i++) {
			int x, y;
			do {
				x = random(-MAXX, MAXX + 1);
				y = random(-MAXX, MAXX + 1);
			} while (!set.add(new Pair(x, y)));
			ret[i] = new Sentinel(x, y, random(0, 4));
		}
		return ret;
	}

	static Sentinel[] genRandomTest() {
		int n = random(1, MAXN + 1);
		Sentinel[] ret = new Sentinel[n];
		Set<Pair> set = new HashSet<Pair>();
		for (int i = 0; i < n; i++) {
			int x, y;
			do {
				x = random(-MAXX, MAXX + 1);
				y = random(-MAXX, MAXX + 1);
			} while (!set.add(new Pair(x, y)));
			ret[i] = new Sentinel(x, y, random(0, 4));
		}
		return ret;
	}

	static Sentinel[] maxAnswerTestV() {
		Sentinel[] ret = new Sentinel[MAXN];
		int x = random(-MAXX, MAXX + 1);
		Set<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < MAXN; i++) {
			int y;
			do {
				y = random(-MAXX, MAXX + 1);
			} while (!set.add(y));
			ret[i] = new Sentinel(x, y, random(0, 2) * 2);
		}
		return ret;
	}

	static Sentinel[] maxAnswerTestH() {
		Sentinel[] ret = maxAnswerTestV();
		for (Sentinel e : ret) {
			int tmp = e.x;
			e.x = e.y;
			e.y = tmp;
			e.dir++;
		}
		return ret;
	}

	static int random(int a, int b) {
		return rand.nextInt(b - a) + a;
	}

	static class Pair {
		int a;
		int b;

		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + a;
			result = prime * result + b;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (a != other.a)
				return false;
			if (b != other.b)
				return false;
			return true;
		}

	}
}
