#K46037. Maximum Adjacent Swaps

    ID: 27887 Type: Default 1000ms 256MiB

Maximum Adjacent Swaps

Maximum Adjacent Swaps

You are given n parcels with weights arranged in an array. Your task is to determine the number of valid adjacent pairs that satisfy the condition: the weight of the left parcel is less than the weight of the right parcel.

Formally, if the weights are represented as an array \(a_1, a_2, \ldots, a_n\), you need to compute the value:

result=i=1n1I(ai<ai+1)\text{result} = \sum_{i=1}^{n-1} I(a_i < a_{i+1})

where \(I(\cdot)\) is an indicator function that equals 1 if the condition inside is true and 0 otherwise.

You should read the input from standard input and print the result to standard output.

inputFormat

The first line of input contains a single integer n (\(0 \leq n \leq 10^5\)), representing the number of parcels. If n is greater than 0, the second line contains n space-separated integers representing the weights of the parcels.

If n is 0, no second line is provided.

outputFormat

Output a single integer which is the number of adjacent pairs \( (a_i, a_{i+1}) \) such that \( a_i < a_{i+1} \).

## sample
0
0