http://www.codechef.com/problems/LEPERMUTlink text

```
#include<iostream>
#include<algorithm>
#define scanint(a) scanf("%d",&a)
using namespace std;
int main()
{
int test;
scanint(test);
while(test--)
{
int n,local_inverse=0,inverse=0;
scanint(n);
int arr[n];
for(int i=1;i<=n;i++)
scanint(arr[i]);
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(arr[i]>arr[j])
inverse++;
}
}
for(int i=1;i<=n;i++)
{
if(arr[i]>arr[i+1])
local_inverse++;
}
if(inverse==local_inverse)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
```