#P10840. Maximum Operations on a Sequence

    ID: 12883 Type: Default 1000ms 256MiB

Maximum Operations on a Sequence

Maximum Operations on a Sequence

Given a sequence \(a_1, a_2, \ldots, a_n\). You are allowed to perform the following operation any number of times:

Operation: Let the current sequence length be \(m\). Choose an integer \(i\) (\(1 \le i \le m-1\)) such that \(a_i \neq a_{i+1}\). Remove \(a_{i+1}\) from the sequence and assign \(a_i\) any integer value of your choice.

Determine the maximum number of operations that can be performed on the sequence.

Observation: If the sequence is not all equal, you can always perform operations until only one element remains (i.e. \(n-1\) operations). Otherwise, if all elements are identical, no operation can be applied.

inputFormat

The first line contains an integer \(n\) (\(1 \le n \le 10^5\)), the length of the sequence.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\), where \(|a_i| \le 10^9\).

outputFormat

Output a single integer, the maximum number of operations that can be performed.

sample

2
1 2
1