#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
int p[MAX];
int m[MAX][MAX];
int n;
void matrix()
{
int i,j,r,k;
memset(m,0
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
int p[MAX];
int m[MAX][MAX];
int n;
void matrix()
{
int i,j,r,k;
memset(m,0