#B2094. Sum of Non-Maximum Elements

    ID: 11176 Type: Default 1000ms 256MiB

Sum of Non-Maximum Elements

Sum of Non-Maximum Elements

Given a sequence of n integers, output the sum of all numbers that are not equal to the maximum number in the sequence.

Let \(M\) denote the maximum value in the sequence. The required answer is computed as:

\[ \sum_{i=1}^{n} a_i \cdot \mathbf{1}_{\{a_i \neq M\}} \]

where \(a_i\) are the elements of the sequence and \(\mathbf{1}_{\{a_i \neq M\}}\) is 1 if \(a_i \neq M\) and 0 otherwise.

inputFormat

The input consists of two lines:

  1. The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of elements in the sequence.
  2. The second line contains n integers separated by spaces. Each integer fits in a 32-bit signed integer.

outputFormat

Output a single integer, which is the sum of all numbers in the sequence that are not equal to the maximum number.

sample

5
1 2 3 3 2
5