#C6298. Minimum Operations to Equalize Bank Balances

    ID: 50042 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Bank Balances

Minimum Operations to Equalize Bank Balances

You are given a list of non-negative integers representing the amount of money in each bank. In one operation, you can select any two banks: increase one bank's balance by 1 and decrease the other bank's balance by 1. The goal is to equalize all bank balances in the minimum number of operations.

The number of operations required can be computed using the formula: [ \text{operations} = \frac{1}{2} \sum_{i=1}^n |a_i - m| ] where (m) is the mean value given by: [ m = \frac{\sum_{i=1}^n a_i}{n} ]

You may assume that the total sum of money is divisible by the number of banks, ensuring that equalization is possible.

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  1. The first line contains a single integer (n), the number of banks.
  2. The second line contains (n) space-separated non-negative integers representing the amount of money in each bank.

outputFormat

Print a single integer to standard output (stdout), which is the minimum number of operations required to equalize all the bank balances.## sample

4
1 3 2 4
2