#C6146. Minimum Operations to Sort an Array
Minimum Operations to Sort an Array
Minimum Operations to Sort an Array
Given an array of n integers, determine the minimum number of operations required to sort the array in non-decreasing order using a specific bitwise AND operation. In this problem, the operation is defined implicitly: if the array is already sorted, no operations are needed; otherwise, exactly two operations are required to achieve a sorted order.
Note that the details of the bitwise AND operation are abstracted away, so your task is simply to check if the array is already sorted and return the corresponding result.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
1. The first line contains a single integer (n) (1 (\leq) n (\leq) 10^5), representing the number of elements in the array.
2. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single integer via standard output (stdout). The output is 0 if the array is already sorted in non-decreasing order; otherwise, output 2.## sample
5
5 3 1 4 2
2
</p>