Last login: Sun Nov 19 16:06:03 on ttys000























        } else {
            size_t start = 0;
            size_t end = N-1;
            while (start+1 != end) {
                auto middle = (start + end) / 2;
                if (b.value < C[middle].value) {
                    end = middle;
                } else if (C[middle].value <= b.value){
                    start = middle;
                }
            }
            count[i] = N-end;
        }
    }
    foreach_reverse(i; 0..N-1) {
        count[i] += count[i+1];
    }
    ulong s = 0;
    foreach (i; 0..N) {
        auto a = A[i];
        size_t idx;
        if (a.value < B[0].value) {
            idx = 0;
        } else if (a.value > B[N-1].value) {
            continue;
        } else {
            size_t start = 0;
            size_t end = N-1;
            while (start+1 != end) {
                auto middle = (start + end) / 2;
                if (a.value < B[middle].value) {
                    end = middle;
                } else if (B[middle].value <= a.value){
                    start = middle;
                }
            }
            idx = end;
        }
        s += count[idx];
    }
    writeln(s);
}