text: #include <bits/stdc++.h>
  using namespace std;
  
  int main(void)
  {
      int n, i;
      double cost[1001], total, average, positive_sum, negative_sum;
  
      while (cin>> n)
      {
          if (n == 0)
              break;
  
          total = 0;
          positive_sum = 0;
          negative_sum = 0;
  
          for (i = 1; i <= n; i++)
          {
              cin>> cost[i];
              total += cost[i];
          }
  
          average = total / n;
          for (i = 1; i <= n; i++)
          {
              double dif = (double)(long)((cost[i] - average) * 100.0) / 100.0;
              if (dif < 0)
                  negative_sum += (-dif);
              else
                  positive_sum += dif;
          }
  
          printf("$%.2lf\n", max(negative_sum, positive_sum));
  
      }
  
      return 0;
  }
  
  
  