def _af_parity(pi):
 n = len(pi)
 a = ([0] * n)
 c = 0
 for j in range(n):
  if (a[j] == 0):
   c += 1
   a[j] = 1
   i = j
   while (pi[i] != j):
    i = pi[i]
    a[i] = 1
 return ((n - c) % 2)

def _af_parity ( pi ) : n = len ( pi ) a = ( [ 0 ] * n ) c = 0 for j in range ( n ) : if ( a [ j ] == 0 ) : c += 1 a [ j ] = 1 i = j while ( pi [ i ] != j ) : i = pi [ i ] a [ i ] = 1 return ( ( n - c ) % 2 )
computes the parity of a permutation in array form .