#include<bits/stdc++.h>
#define MX 1000007
#define ll long long
#define ull unsigned long long
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=0;j<n;j++)
using namespace std;
int x,n;
int inCount(int *a)
{
int cnt=0;
for(int i=0;i<x;i++){
for(int j=i+1;j<x;j++)
if(a[i]>a[j] && a[i] && a[j])
cnt++;
}
return cnt;
}
int main()
{
int position;
cin>>n;
int ara[n][n],trace[n*n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>ara[i][j];
trace[x++]=ara[i][j];
if(ara[i][j]==0)
position=n-i;
}
}
cout<<"Position "<<position<<endl;
int cnt=inCount(trace);
cout<<"Invertion: "<<cnt<<endl;
if(n&1 && cnt%2==0)
cout<<"Solveable!"<<endl;
else if(n%2==0 && cnt%2==0 && position%2==1)
cout<<"Solvable!"<<endl;
else if(n%2==0 && cnt%2==1 && position%2==0)
cout<<"Solvable!"<<endl;
else
cout<<"Unsolvable!"<<endl;
return 0;
}
No comments