static int kthHelper(int[]A, int[]B, int k) {
		int m=A.length, n=B.length;
		if (m==0||n==0)
			return m==0?B[k-1]:A[k-1];
			int l=Math.max(0, k-1-n), r=Math.min(k-1, m);
			while (true) {
				int i=l+(r-l)/2;
				int j=k-1-i;
				int a=i==m?Integer.MAX_VALUE:A[i];
				int b=j==n?Integer.MAX_VALUE:B[j];
				int a_1=i==0?Integer.MIN_VALUE:A[i-1];
				int b_1=j==0?Integer.MIN_VALUE:B[j-1];
				if (a_1<=b&&b<=a)
					return b;
				if (b_1<=a&&a<=b)
					return a;
				if (a_1<=b) {
					l=i+1;
				} else {
					r=i-1;
				}
			}
	}