public int findKth(int A[], int B[], int as, int ae, int bs, int be, int k) {
        if(as > ae) return B[bs + k - 1];
        if(bs > be) return A[as + k - 1];
        int am = (ae - as) / 2 + as, bm = (be - bs) / 2 + bs;
        int l = am - as + bm - bs + 1;
        if(A[am] >= B[bm]) {
            if(k > l) return findKth(A, B, as, ae, bm+1, be, k - (bm - bs + 1)); // bug, k - ?
            else return findKth(A, B, as, am-1, bs, be, k);
        } else {
            if(k > l) return findKth(A, B, am+1, ae, bs, be, k - (am - as + 1));
            else return findKth(A, B, as, ae, bs, bm-1, k);
        }
    }