#include <iostream>
#include <iomanip>

int main(int argc, const char* argv[]) {
    int total_rows, total_cols;

    std::cout << "Please enter number of rows: ";
    std::cin >> total_rows;

    std::cout << "Please enter number of columns: ";
    std::cin >> total_cols;

    int* matrix = new int[total_rows*total_cols];

    std::cout << "Initialize matrix: \n";

    for (int row = 0; row < total_rows; row++) {
        for (int col = 0; col < total_cols; col++) {
            std::cin >> matrix[col + row*total_rows];
        }
    }

    std::cout << "Matrix:\n";

    for (int row = 0; row < total_rows; row++) {
        for (int col = 0; col < total_cols; col++) {
            std::cout << std::setw(3) << matrix[col + row*total_rows];
        }
        std::cout << "\n";
    }

    int row_number;
    std::cout << "\nEnter row number (zero-based) to calculate sum for: ";
    std::cin >> row_number;

    int sum = 0;
    for (int col = 0; col < total_cols; col++) {
        sum += matrix[col + row_number*total_cols];
    }

    std::cout << "Sum = " << sum << "\n";

    delete[] matrix;
}