#include <iostream>

void fillMatrixK(int m, int n, int matrix[100][100]) {
    int value = 1;
    int top = 0, bottom = m - 1, left = 0, right = n - 1;

    while (top <= bottom && left <= right) {
        for (int j = left; j <= right; ++j) {
            matrix[top][j] = value;
        }
        for (int i = top + 1; i <= bottom; ++i) {
            matrix[i][right] = value;
        }
        if (top != bottom) {
            for (int j = right - 1; j >= left; --j) {
                matrix[bottom][j] = value;
            }
        }
        if (left != right) {
            for (int i = bottom - 1; i > top; --i) {
                matrix[i][left] = value;
            }
        }
        ++value;
        ++top;
        --bottom;
        ++left;
        --right;
    }
}

int main() {
    int m = 5, n = 5;
    int matrix[100][100] = {0};

    fillMatrixK(m, n, matrix);

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            std::cout << matrix[i][j] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}

