import java.io.*; import java.util.*; /** * Read in bitstrings and keep track of only those strings that * increase the rank of the space. This is done by performing * Gaussian Elimination each time a new string is added. * * Get the resulting set of bitstrings in reduced row echelon form * and track the operations used to do this. * Apply those operations to each target bitstring. Iterate over * the resulting bitstring to determine the largest index required * from the initial set of bitstrings. * * @author Finn Lidbetter */ public class nk3_mk2 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String[] s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int m = Integer.parseInt(s[1]); int k = Integer.parseInt(s[2]); BitSet[] arr = new BitSet[k*4]; for (int i=0; i minIndex = new HashMap<>(); int maxColumn = 0; for (int i=0; i0) { BitSet[] copy = makeCopy(arr, maxColumn+1); rref(copy, maxColumn+1, false); if (isConsistent(copy, maxColumn+1)) { if (minSkip==-1) minSkip = i; continue; } minIndex.put(maxColumn, i); maxColumn++; } else { minIndex.put(maxColumn, i); maxColumn++; } } ArrayList ops = rref(arr, maxColumn+1, true); int[] setColumn = new int[4*k]; Arrays.fill(setColumn, -1); for (int c=0; c=0; j--) { if (binaryArray[j]==1) { int bitStringIndex = setColumn[j]; if (bitStringIndex==-1) { System.out.println(-1); } else { System.out.println(minIndex.get(bitStringIndex) + 1); } break; } } } } static void printBitSetArr(BitSet[] arr, int columns) { StringBuilder sb = new StringBuilder(); for (int i=0; i 0) ? 1 : 0; } } return arr; } static ArrayList rref(BitSet[] arr, int columns, boolean returnOperations) { int n = arr.length; int m = columns; int r = 0; ArrayList ops = new ArrayList<>(); for (int i = 0; i < m-1 && r ops) { for (Operation op: ops) { if (op.isSwap) { int tmp = arr[op.r1]; arr[op.r1] = arr[op.r2]; arr[op.r2] = tmp; } else { arr[op.r1] ^= arr[op.r2]; } } } } class Operation { int r1; int r2; boolean isSwap; public Operation(int rr1, int rr2, boolean isSwap) { r1 = rr1; r2 = rr2; this.isSwap = isSwap; } }