#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; int R, K; int H, W; pii convert(int x, int y) { y /= K; x /= K; if (R == 0) { return make_pair(x, y); } else if (R == 90) { return make_pair(y, H - x - 1); } else if (R == 180) { return make_pair(W - x - 1, H - y - 1); } else { return make_pair(W - y - 1, x); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> R >> K; cin >> H >> W; vector> image(H, vector(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> image[i][j]; } } const int h = (R % 180 == 0) ? H * K : W * K; const int w = (R % 180 == 0) ? W * K : H * K; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { const auto p = convert(x, y); show(p); cout << image[p.second][p.first]; } cout << endl; } return 0; }