#include <iostream>
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ** x = new int *[n];
for (int i = 0; i < n; i++)
x[i] = new int[m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> x[i][j];
cout << m << " " << n;
cout << endl;
for (int j = 0; j < m; j++){
for (int i = n - 1; i >= 0; i--)
cout << x[i][j] << " ";
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLCBtOwoJY2luID4+IG4gPj4gbTsKCWludCAqKiB4ID0gbmV3IGludCAqW25dOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIAoJICAgIHhbaV0gPSBuZXcgaW50W21dOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCgkJZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspCgkJCWNpbiA+PiB4W2ldW2pdOwoJY291dCA8PCBtIDw8ICIgIiA8PCBuOwoJY291dCA8PCBlbmRsOwoJZm9yIChpbnQgaiA9IDA7IGogPCBtOyBqKyspewoJCWZvciAoaW50IGkgPSBuIC0gMTsgaSA+PSAwOyBpLS0pCgkJCWNvdXQgPDwgeFtpXVtqXSA8PCAiICI7CgkJY291dCA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=