// Задача "Две последовательности"
// 10-ая Интернет-олимпиада сезона 2007-2008, базовый уровень
// Автор задачи: Федор Царев, tsarev@rain.ifmo.ru
// Автор решения: Сергей Поромов, poromov@rain.ifmo.ru

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

public class twoseq_sp implements Runnable {

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

	public void run() {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	BufferedReader br;

	PrintWriter out;

	StringTokenizer st;

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

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

	void myAssert(boolean e, String s) {
		if (!e) {
			throw new Error("Assertion failure " + s);
		}
	}

	private static final String FILENAME = "twoseq";

	public void solve() throws IOException {
		br = new BufferedReader(new FileReader(FILENAME + ".in"));
		out = new PrintWriter(FILENAME + ".out");
		int n = nextInt();
		int k = nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		for (int i = 0; i < n; i++) {
			b[i] = nextInt();
			c[i] = (b[i] - a[i] + k) % k;
		}
		int i = 0;
		boolean fl = false;
		int j = 0;
		while (!fl) {
			for (j = i + 1; j < n; j++) {
				if (c[j] == c[i]) {
					fl = true;
					break;
				}
			}
			i++;
		}
		i--;
		out.println(n - 1);
		out.println((i + 1) + " " + (j + 1) + " " + c[i]);
		for (int ii = i + 1; ii < j; ii++) {
			c[ii] = (c[ii] - c[i] + k) % k;
		}
		for (int ii = 0; ii < n; ii++) {
			if (ii != i && ii != j) {
				out.println((ii + 1) + " " + (ii + 1) + " " + c[ii]);
			}
		}
		out.close();
	}
}
