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

public class TestGen {
	public static void main(String[] args) {
		new TestGen().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

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

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

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

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

	class Edge {
		int from;
		int to;

		public Edge(int a, int b) {
			from = a;
			to = b;
		}
	}

	int tNumber;

	Random rnd;

	void print(ArrayList<Edge> a, int n, Boolean... booleans)
			throws IOException {
		boolean x = (booleans.length == 0);
		if (tNumber < 10) {
			out = new PrintWriter("../tests/0" + tNumber);
		} else {
			out = new PrintWriter("../tests/" + tNumber);
		}
		for (Edge e : a) {
			if (rnd.nextBoolean()) {
				int t = e.to;
				e.to = e.from;
				e.from = t;
			}
		}
		Collections.shuffle(a, rnd);
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			arr.add(i + 1);
		}
		Collections.shuffle(arr,rnd);
		for (Edge e : a) {
			// System.err.println(n + " " + e.to + " " + e.from);
			e.to = arr.get(e.to);
			e.from = arr.get(e.from);
		}
		out.println(n);
		for (Edge e : a) {
			out.println(e.from + " " + e.to + " "
					+ ((x) ? (rnd.nextInt(100) + 1) : 100));
		}
		out.close();
		tNumber++;
	}

	int[][] rename(int[][] a) {
		int n = a.length + 1;
		int[][] res = new int[n - 1][2];
		ArrayList<Integer> perm = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			perm.add(i);
		}
		Collections.shuffle(perm, rnd);
		for (int i = 0; i < n - 1; i++) {
			res[i][0] = perm.get(a[i][0]);
			res[i][1] = perm.get(a[i][1]);
		}
		return res;
	}

	ArrayList<Edge> genrnd(int n) {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 1; i < n; i++) {
			res.add(new Edge(i, rnd.nextInt(i)));
		}
		return res;
	}

	ArrayList<Edge> genline(int n) {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 1; i < n; i++) {
			res.add(new Edge(i, i - 1));
		}
		return res;
	}

	ArrayList<Edge> genstar(int n) {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 1; i < n; i++) {
			res.add(new Edge(i, 0));
		}
		return res;
	}

	ArrayList<Edge> gen(int n, int type) {
		if (type == 0) {
			return genrnd(n);
		}
		if (type == 1) {
			return genline(n);
		}
		if (type == 2) {
			return genstar(n);
		}
		return null;
	}

	void genrandom(int c1, int c2, int c3, int n) throws IOException {
		ArrayList<Integer> cmp = new ArrayList<Integer>();
		for (int i = 0; i < c1; i++) {
			cmp.add(0);
		}
		for (int i = 0; i < c2; i++) {
			cmp.add(1);
		}
		for (int i = 0; i < c3; i++) {
			cmp.add(2);
		}
		int p = cmp.size();
		Collections.shuffle(cmp, rnd);
		int[] sum = new int[p];
		Arrays.fill(sum, 1);
		n -= p;
		for (int i = 0; i < n; i++) {
			sum[rnd.nextInt(p)]++;
		}
		int[] st = new int[p];
		ArrayList<Edge> res = gen(sum[0], cmp.get(0));
		for (int i = 1; i < p; i++) {
			st[i] = st[i - 1] + sum[i - 1];
			int prv = rnd.nextInt(i);
			res.add(new Edge(st[prv] + rnd.nextInt(sum[prv]), st[i]
					+ rnd.nextInt(sum[i])));
			ArrayList<Edge> cur = gen(sum[i], cmp.get(i));
			for (Edge e : cur) {
				e.from += st[i];
				e.to += st[i];
				res.add(e);
			}
		}
		print(res, n + p);
	}

	void genBinary(int n) throws IOException {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 1; i < n; i++) {
			res.add(new Edge((i - 1) / 2, i));
		}
		print(res, n);
	}

	void genFour(int n) throws IOException {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 0; i < n; i++) {
			for (int k = 1; k <= 4; k++) {
				if (i * 4 + k < n) {
					res.add(new Edge(i * 4 + k, i));
				}
			}
		}
		print(res, n);
	}

	void genMaxLine(int n) throws IOException {
		ArrayList<Edge> res = new ArrayList<Edge>();
		for (int i = 0; i < n - 1; i++) {
			res.add(new Edge(i, i + 1));
		}
		print(res, n, true);
	}

	void gens(int n, int m) throws IOException {
		genrandom(0, 1, 0, rnd.nextInt(n) + m);
		genrandom(0, 0, 1, rnd.nextInt(n) + m);
		genrandom(0, rnd.nextInt(3) + 2, 0, rnd.nextInt(n) + m);
		genrandom(0, 0, rnd.nextInt(3) + 2, rnd.nextInt(n) + m);
		for (int i = 0; i < 5; i++) {
			genrandom(rnd.nextInt(3), rnd.nextInt(3), rnd.nextInt(3),
					rnd.nextInt(n) + m);
		}

		genBinary(rnd.nextInt(n) + m);
		genFour(rnd.nextInt(n) + m);
		genMaxLine(n + m);

	}

	public void solve() throws IOException {
		tNumber = 1;
		rnd = new Random(23);
		int n = 10;
		for (int i = 0; i < 2; i++) {
			genrandom(1, 0, 0, rnd.nextInt(6) + 5);
		}
		for (int i = 0; i < 3; i++) {
			genrandom(1, 0, 0, i + 1);
		}
		gens(n, 2 * n);

		n = 500;

		for (int i = 0; i < 5; i++) {
			genrandom(1, 0, 0, rnd.nextInt(n) + 2 * n);
		}
		gens(n, 2 * n);
		n = 50000;
		for (int i = 0; i < 5; i++) {
			genrandom(1, 0, 0, rnd.nextInt(n) + n);
		}
		gens(n, n);
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}