input: from typing import List
  
  def gini(x: List[int]) -> float:
      """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.0
      x_sorted = sorted(x)
      total_sum = sum(x_sorted)
      cumulative_sum = 0.0
      gini_sum = 0.0
      for i in range(n):
          cumulative_sum += x_sorted[i]
          gini_sum += (i + 1) * x_sorted[i]
      return (2 * gini_sum / total_sum - (n + 1)) / n