#K13491. The Hardness of Sorting

    ID: 23924 Type: Default 1000ms 256MiB

The Hardness of Sorting

The Hardness of Sorting

You are given n boxes with integer labels. The boxes are arranged in an arbitrary order and need to be sorted in non-decreasing order using a specific sorting mechanism.

In each cycle, the program performs a single pass similar to bubble sort: it compares each pair of adjacent boxes and swaps them if they are in the wrong order. The process repeats until no swaps are needed, at which point the list is sorted. The hardness of sorting is defined as the number of complete cycles required to achieve this sorted order. Mathematically, if the list is already sorted, then the hardness is defined to be \(1\); otherwise, it is the number of cycles until no swap occurs.

Your task is to compute and output the hardness of sorting given the initial labels of the boxes.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer \(n\) representing the number of boxes.
  • The second line contains \(n\) space-separated integers representing the labels of the boxes.

outputFormat

Output a single integer to stdout which is the number of cycles required to sort the boxes using the described mechanism.

## sample
5
4 3 2 1 5
4

</p>