double var(int N1[], int N2[], double weight[]) {
		int k = N1.length;

		// Calculate R1 and R2
		int R1 = 0, R2 = 0;
		for (int i = 0; i < k; i++) {
			R1 += N1[i];
			R2 += N2[i];
		}

		// Total
		int N = R1 + R2;

		// Calculate first sum (see reference)
		double sum1 = 0;
		for (int i = 0; i < k; i++) {
			int Ci = N1[i] + N2[i];
			sum1 += (weight[i] * weight[i]) * Ci * (N - Ci);
		}

		// Calculate second sum
		double sum2 = 0;
		for (int i = 0; i < (k - 1); i++) {
			int Ci = N1[i] + N2[i];
			for (int j = i + 1; j < k; j++) {
				int Cj = N1[j] + N2[j];
				sum2 += weight[i] * weight[j] * Ci * Cj;
			}
		}

		// Calculate variance
		double var = ((double) R1 * R2) / N * (sum1 - 2.0 * sum2);

		return var;
	}