input: def gini(x):
      """Calculate Gini Coefficient of a given dataset.
      >>> gini(np.array([2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,21]))
      0.605
      """
output:     
      n = len(x)
      if n == 0:
          return 0
      x_sorted = np.sort(x)
      index = np.arange(1, n + 1)
      return (n + 1 - 2 * np.sum(index * x_sorted) / (n * np.sum(x_sorted))) / n
  