int Gcd( int a , int b ){ return b==0?a:Gcd( b , a%b ); }
int Lcm( int a , int b ){ return a/Gcd( a , b )*b; }
int Abs( int a ){ return a<0?-a:a; }
int a[maxn][maxn];
int x[maxn];
int Gauss( int n , int m )
{
int k,col,max_r;
for ( k=0,col=0 ; k<n&&col<m ; k++,col++ )
{
max_r = k;
for ( int i=k+1 ; i<n ; i++ )
if ( Abs( a[i][col] )>Abs( a[max_r][col] ) )
max_r = i;
if ( max_r!=k )
for ( int i=col ; i<=m ; i++ )
swap( a[k][i] , a[max_r][i] );
if ( a[k][col]==0 )
{
k--;
continue;
}
for ( int i=k+1 ; i<n ; i++ )
{
if ( a[i][col]!=0 )
{
int LCM = Lcm( Abs( a[i][col] ) , Abs( a[k][col] ) );
int ta = LCM/Abs( a[i][col] );
int tb = LCM/Abs( a[k][col] );
if ( a[i][col]*a[k][col]<0 )
tb = -tb;
for ( int j=col ; j<=m ; j++ )
a[i][j] = a[i][j]*ta-a[k][j]*tb;
}
}
}
//无解
for ( int i=k ; i<n ; i++ )
if ( a[i][m]!=0 ) return -1;
//自由元/无限解
if ( k<m ) return m-k;
//唯一解
for ( int i=n-1 ; i>=0 ; i-- )
{
int temp = a[i][m];
for ( int j=i+1 ; j<m ; j++ )
if ( a[i][j]!=0 )
temp -= a[i][j]*x[j];
//无整数解
if( temp%a[i][i]!=0 ) return -2;
x[i] = temp/a[i][i];
}
//有解
return 0;
}