def z2_reduction(n, N):
    """
    Performs so-called Z2-symmetry reduction on a parity representation.
    
    :param n: any positive integer
    :param N: number of bits/qubits used in representing the integer `n`
    :returns: the integer representing the Z2 reduced parity value
    """
    lower_mask = 2 ** (N//2 - 1) - 1
    upper_mask = lower_mask << N//2
    
    z2_reduced = (n & lower_mask) + ((n & upper_mask) >> 1)
    
    #print(f'{n} = {n:0{N}b} : {z2_reduced:0{N-2}b} {lower_mask:0{N}b} {upper_mask:0{N}b}')
    return z2_reduced