#include <iostream>
#include <stdexcept>

void add_column(int** matrix, int rows, int cols, int* column, int position, int**& new_matrix) {
    if (rows != cols) {
        throw std::invalid_argument("Количество элементов в новом столбце должно совпадать с количеством строк матрицы.");
    }

    new_matrix = new int*[rows];
    for (int i = 0; i < rows; ++i) {
        new_matrix[i] = new int[cols + 1];
        for (int j = 0; j < position; ++j) {
            new_matrix[i][j] = matrix[i][j];
        }
        new_matrix[i][position] = column[i];
        for (int j = position; j < cols; ++j) {
            new_matrix[i][j + 1] = matrix[i][j];
        }
    }
}

int main() {
    int rows = 3, cols = 3;
    int** matrix = new int*[rows];
    for (int i = 0; i < rows; ++i) {
        matrix[i] = new int[cols];
    }

    matrix[0][0] = 1; matrix[0][1] = 2; matrix[0][2] = 3;
    matrix[1][0] = 4; matrix[1][1] = 5; matrix[1][2] = 6;
    matrix[2][0] = 7; matrix[2][1] = 8; matrix[2][2] = 9;

    int column[] = {10, 11, 12};
    int position = 1;
    int** new_matrix;

    add_column(matrix, rows, cols, column, position, new_matrix);

    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols + 1; ++j) {
            std::cout << new_matrix[i][j] << " ";
        }
        std::cout << std::endl;
    }

    for (int i = 0; i < rows; ++i) {
        delete[] matrix[i];
        delete[] new_matrix[i];
    }
    delete[] matrix;
    delete[] new_matrix;

    return 0;
}

