using namespace std;
bool cmp (int x, int y){
return x > y;
}
int main (){
int n, m;
cin >> n >> m;
int a[n][m] = {{1, 4, 7, 11, 15},{2, 5, 8, 12, 19},{3, 6, 9, 16, 22},
{10, 13, 14, 17, 24}, {18, 21, 23, 26, 30}};
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++){
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
sort (&a[0][0], &a[0][0] + (n)*(m));
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++){
printf ("%4d ", a[i][j]);
}
cout << endl;
}
int target;
cin >> target;
int i = n - 1, j = 0;
while (i >= 0 && j <= m - 1){
if (target > a[i][j]) {
j ++;
// cout << "j = j + 1 = " << j << endl;
}
if (target < a[i][j]) {
i --;
// cout << "i = i - 1 = " << i << endl;
}
if (target == a[i][j]) {
cout << "i = " << i << " j = " << j << endl;
return 0;
}
}
cout << "没有";
cout << endl;
return 0;
}