#K75732. Equalize Payments

    ID: 34485 Type: Default 1000ms 256MiB

Equalize Payments

Equalize Payments

You are given a list of payments made by friends. The goal is to calculate how much each friend should pay or receive so that everyone ends up contributing equally. Let the total sum be \(S = \sum_{i=1}^{n} payment_i\) and define the fair share as \(F = \text{round}\left(\frac{S}{n}\right)\). For each friend, compute the difference \(d_i = payment_i - F\). In the rare case that \(\sum_{i=1}^{n} d_i \neq 0\) due to rounding, adjust the last friend’s difference so that the overall imbalance is zero.

Your task is to read the number of friends and their payments from standard input, calculate these differences, and output them in order on a single line with space-separated integers. It is guaranteed that the final sum of differences is zero.

inputFormat

The input is provided from standard input in the following format:

  • The first line contains an integer \(n\) denoting the number of friends.
  • The second line contains \(n\) space-separated integers representing the payment amounts.

outputFormat

Output a single line to standard output containing \(n\) space-separated integers. The \(i\)-th integer represents the amount that friend \(i\) should pay (if negative) or receive (if positive) to equalize the payments. The sum of these differences is zero.

## sample
4
10 20 30 40
-15 -5 5 15