#include <iostream>
#include <iomanip>
#include <memory>
#include <fstream>
#include <sstream>
struct SquareMatrix
{
SquareMatrix(unsigned dimensions)
: _dim(dimensions), _matrix(new int[_dim*_dim]) {}
unsigned dimension() const { return _dim; }
int& operator()(unsigned row, unsigned col)
{
return _matrix[row * _dim + col];
}
int operator()(unsigned row, unsigned col) const
{
return _matrix[row * _dim + col];
}
private:
unsigned _dim;
std::unique_ptr<int[]> _matrix;
};
std::ostream& operator<<(std::ostream& os, const SquareMatrix& mat)
{
for (unsigned i = 0; i < mat.dimension(); ++i)
{
for (unsigned j = 0; j < mat.dimension(); ++j)
os << mat(i, j) << ' ';
os << '\n';
}
return os;
}
std::istream& operator>>(std::istream& is, SquareMatrix& mat)
{
for (unsigned i = 0; i < mat.dimension(); ++i)
for (unsigned j = 0; j < mat.dimension(); ++j)
is >> mat(i, j);
return is;
}
int main()
{
// std::ifstream in("matrix.txt");
std::istringstream in("3\n5 7 10\n5 3 2\n0 6 8");
unsigned size;
in >> size;
SquareMatrix matrix(size);
in >> matrix;
std::cout << matrix << '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzc3RyZWFtPgoKCnN0cnVjdCBTcXVhcmVNYXRyaXgKewogICAgU3F1YXJlTWF0cml4KHVuc2lnbmVkIGRpbWVuc2lvbnMpIAogICAgICAgIDogX2RpbShkaW1lbnNpb25zKSwgX21hdHJpeChuZXcgaW50W19kaW0qX2RpbV0pIHt9CgogICAgdW5zaWduZWQgZGltZW5zaW9uKCkgY29uc3QgeyByZXR1cm4gX2RpbTsgfQoKICAgIGludCYgb3BlcmF0b3IoKSh1bnNpZ25lZCByb3csIHVuc2lnbmVkIGNvbCkKICAgIHsKICAgICAgICByZXR1cm4gX21hdHJpeFtyb3cgKiBfZGltICsgY29sXTsKICAgIH0KCiAgICBpbnQgb3BlcmF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