#include <iostream>

void fillMatrixA(int m, int n, int matrix[100][100], int i, int j) {
    int directions[8][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
    int queue[10000][2];
    int front = 0, rear = 0;

    queue[rear][0] = i;
    queue[rear][1] = j;
    rear++;
    matrix[i][j] = 1;

    while (front < rear) {
        int x = queue[front][0];
        int y = queue[front][1];
        front++;
        int value = matrix[x][y];

        for (int k = 0; k < 8; ++k) {
            int nx = x + directions[k][0];
            int ny = y + directions[k][1];
            if (nx >= 0 && nx < m && ny >= 0 && ny < n && matrix[nx][ny] == 0) {
                matrix[nx][ny] = value + 1;
                queue[rear][0] = nx;
                queue[rear][1] = ny;
                rear++;
            }
        }
    }
}

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

    fillMatrixA(m, n, matrix, i, j);

    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;
}
        for (auto& dir : directions) {
