input: Write a function to calculate the Gini coefficient of a given dataset.
  assert 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
  assert gini(np.array([1,2,3,4,5])) == 0.27999999999999997
  assert gini(np.array([1,1,1,1,1])) == 0.0
  assert gini(np.array([10, 10, 20, 20, 30, 30])) == 0.2666666666666667
output: def gini(data):
      n = len(data)
      if n == 0:
          return 0
      data_sorted = sorted(data)
      cum_sum = [0] * n
      for i in range(n):
          cum_sum[i] = cum_sum[i - 1] + data_sorted[i]
      total_sum = cum_sum[-1]
      gini_sum = 0
      for i in range(n):
          gini_sum += (i + 1) * data_sorted[i]
      gini_coefficient = (2 * gini_sum - n * total_sum) / (n * total_sum)
      return gini_coefficient