def compute_mean_C (counts, i, j):
    """
    Computes the mean value <psi | Z_i Z_j |psi> with the results of the measures.
    """
    total = sum(counts.values())
    n = len( list(counts.keys())[0] )

    # Probabilities of having ( psi & (2^i + 2^j) ) = ab with a, b in {0,1}
    p_00 = 0
    p_01 = 0
    p_10 = 0
    p_11 = 0

    for key in counts:
        if key[n-1-i] == '0' and key[n-1-j] == '0':
            p_00 += counts[key]
        elif key[n-1-i] == '0' and key[n-1-j] == '1':
            p_01 += counts[key]
        elif key[n-1-i] == '1' and key[n-1-j] == '0':
            p_10 += counts[key]
        else:
            p_11 += counts[key]

    return (p_00 - p_01 - p_10 - p_11) / total