public int findKth(int[] A, int aL, int aR, int[] B, int bL, int bR, int k) {

		int m = aR - aL + 1;
		int n = bR - bL + 1;

		if (m > n)
			return findKth(B, bL, bR, A, aL, aR, k);
		if (m == 0)
			return B[k - 1];
		if (k == 1)
			return Math.min(A[aL], B[bL]);

		int partA = Math.min(k / 2, m);
		int partB = k - partA;

		if (A[aL + partA - 1] < B[bL + partB - 1]) {
			return findKth(A, aL + partA, aR, B, bL, bR, k - partA);
		} else if (A[aL + partA - 1] > B[bL + partB - 1]) {
			return findKth(A, aL, aR, B, bL + partB, bR, k - partB);
		} else {
			return A[aL + partA - 1];
		}
	}