#C5470. Redistribute Books on Racks

    ID: 49123 Type: Default 1000ms 256MiB

Redistribute Books on Racks

Redistribute Books on Racks

You are given n racks, each containing a certain number of books. Your task is to determine if it is possible to redistribute the books so that each rack ends up with the same number of books. However, no rack is allowed to be empty after the redistribution.

Formally, let \( n \) be the number of racks and \( b_1, b_2, \dots, b_n \) be the number of books on each rack. Let \( T = b_1 + b_2 + \cdots + b_n \) be the total number of books. A valid redistribution is possible if and only if

\( T \mod n = 0 \)

and each rack originally contains at least one book. When a valid redistribution is possible, each rack will have \( \frac{T}{n} \) books after redistribution; otherwise, output \( -1 \).

inputFormat

The input is given from stdin and consists of two lines:

  1. The first line contains a single integer \( n \) representing the number of racks.
  2. The second line contains \( n \) space-separated integers, each representing the number of books on a rack.

outputFormat

Print a single integer to stdout. This integer should be the number of books on each rack after even redistribution if it is possible to redistribute the books under the given constraints, or \( -1 \) if it is impossible.

## sample
5
6 9 3 6 6
6