/* * Solution Template for Human LCD II * * Australian Informatics Olympiad 2026 Invitationals * * This file is provided to assist with reading of input and writing of output * for the problem. You may modify this file however you wish, or * you may choose not to use this file at all. */ import java.io.*; class Solution { /* R and C are the dimensions of the display; R * C is at most 1000. */ private static int R; private static int C; /* * A and B contain the initial and target colours. Both arrays start from 0. */ private static int A[][] = new int[1005][1005]; private static int B[][] = new int[1005][1005]; /* * The ith instruction changes cell (X[i], Y[i]) to colour V[i]; coordinates * are 1-based. */ private static int L; private static int X[] = new int[1000005]; private static int Y[] = new int[1000005]; private static int V[] = new int[1000005]; /* * Read the next token from the input file. * Tokens are separated by whitespace, i.e., spaces, tabs and newlines. * If end-of-file is reached then an empty string is returned. */ private static String readToken(BufferedReader in) throws IOException { StringBuffer ans = new StringBuffer(); int next; /* Skip any initial whitespace. */ next = in.read(); while (next >= 0 && Character.isWhitespace((char)next)) next = in.read(); /* Read the following token. */ while (next >= 0 && ! Character.isWhitespace((char)next)) { ans.append((char)next); next = in.read(); } return ans.toString(); } public static void main(String[] args) throws IOException { /* Open the input and output streams for stdin and stdout. */ BufferedReader input_reader = new BufferedReader(new InputStreamReader( System.in)); BufferedWriter output_writer = new BufferedWriter(new OutputStreamWriter( System.out)); /* Read the two R by C grids. */ R = Integer.parseInt(readToken(input_reader)); C = Integer.parseInt(readToken(input_reader)); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { A[i][j] = Integer.parseInt(readToken(input_reader)); } } for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { B[i][j] = Integer.parseInt(readToken(input_reader)); } } /* * TODO: Construct at most one million legal instructions transforming A * into B. * For full marks, minimise the number of instructions. */ /* * An empty instruction sequence is shown below; it is correct only when A * equals B. */ output_writer.write(L + "\n"); for (int i = 0; i < L; i++) { output_writer.write(X[i] + " " + Y[i] + " " + V[i] + "\n"); } /* Close the input_reader and output_writer. */ input_reader.close(); output_writer.close(); } }