#K70352. Maximizing Pair Count with One Swap Operation

    ID: 33289 Type: Default 1000ms 256MiB

Maximizing Pair Count with One Swap Operation

Maximizing Pair Count with One Swap Operation

You are given an integer n and an array a consisting of n integers. You are allowed to perform exactly one swap operation between two distinct elements in the array. Your task is to determine the maximum possible number of pairs (i, j) such that 1 ≤ i < j ≤ n and ai < aj after performing the one swap operation.

The maximum number of such pairs achievable in any array of size n (when the array is in strictly increasing order) can be expressed using the formula:

\(\frac{n(n-1)}{2}\)

Note: For the purpose of this problem, you are expected to output \(\frac{n(n-1)}{2}\) as the answer regardless of the initial order of the array.

inputFormat

The first line of input contains a single integer n, representing the number of elements in the array.

The second line contains n space-separated integers, representing the elements of the array a.

Input Format:

n
 a1 a2 ... an

outputFormat

Output a single integer which is the maximum possible number of pairs (i, j) satisfying ai < aj after performing exactly one swap operation.

Output Format:

result
## sample
5
5 3 1 4 2
10

</p>