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

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

public class twoseq_ft implements Runnable {

	private Scanner in;
	private PrintWriter out;
	String fname = "twoseq";

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

	void apply(int[] a, int l, int r, int d, int k) {
		for (int i = l; i <= r; i++) {
			a[i] += d;
			a[i] %= k;
		}	
	}

	public void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		myAssert(1 <= n && n <= 1000, "n is out of bounds");
		myAssert(1 <= k && k <= 1000, "k is out of bounds");
		myAssert(n > k, "n <= k");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			myAssert(0 <= a[i] && a[i] < k, "a[" + i + "] is out of bounds");
		}
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = in.nextInt();
			myAssert(0 <= b[i] && b[i] < k, "b[" + i + "] is out of bounds");
		}
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = (a[i] - b[i] + k) % k;
		}
		ArrayList<String> ans = new ArrayList<String>();
		outer:
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (c[i] == c[j]) {
					ans.add((i + 1) + " " + (j + 1) + " " + (k - c[i]));
					apply(c, i, j, k - c[i], k);
					break outer;					
				}
			}
		}
		for (int i = 0; i < n; i++) {
			if (c[i] != 0) {
				ans.add((i + 1) + " " + (i + 1) + " " + (k - c[i]));
			}
		}
		out.println(ans.size());
		for (String s : ans) {
			out.println(s);
		}
	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}		
	}

	public twoseq_ft() {
		try {
			in = new Scanner(new File(fname + ".in"));
			out = new PrintWriter(new File(fname + ".out"));
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}


	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new Thread(new twoseq_ft()).start();
	}

}                       