input: def gini(x):
      """Calculate Gini Coefficient of a given dataset.
      >>> gini([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
      total_sum = sum(x)
      squared_sum = sum(xi ** 2 for xi in x)
      gini_coeff = 1 - (squared_sum / (total_sum ** 2))
      return round(gini_coeff * n / (n - 1), 3)