You will be given an array of length . Print the return value of the following function.
int function(int A[], int N) {
int cnt = 0;
for(int i = 1; i <= N; i++) {
int x = A[i];
int j = i-1;
while(j >= 1 && A[j] > x) {
A[j+1] = A[j];
j--;
cnt++;
}
A[j+1] = x;
}
return cnt;
}
First line of input contains an integer , the length of the array.
The second line contains integers , the elements of the array.
Print the return value of the function.
Input | Output |
---|---|
5 3 1 5 1 2 | 5 |