def soft_alldifferent(x,p):
  """
  soft_alldifferent(x,p)

  p is the number of pairs that have the same value.
  
  See http://www.emn.fr/z-info/sdemasse/gccat/Csoft_alldifferent_ctr.html
  """
  n = len(x)
  return [p == sum([x[i] == x[j] for i in range(n) for j in range(i+1,n)])]