#include <iostream>
#include <vector>
#include <utility>
using namespace std;
template <class T>
class Matrix {
vector<vector<T>> m;
public:
Matrix (int r, int c) : m(r, vector<int>(c, T())) { }
void show() {
cout << "Matrix("<<m.size()<<","<<m[0].size()<<")"<<endl;
for (int i=0; i<m.size(); i++) {
cout <<" ";
for (int j=0; j<m[i].size(); j++)
cout << m[i][j]<<" ";
cout<<endl;
}
}
vector<T>& operator[] (int r) { return m[r]; }
T& operator[] (pair<int, int> p) { return m[p.first][p.second]; }
T& operator() (int r, int c) { return m[r][c]; }
};
int main() {
Matrix<int> a(2,2);
a.show();
a[{0,0}] = 3;
int b = a[{1,0}];
a.show();
a[0][1] = 4;
int c = a[0][1];
a.show();
a(1,0) = 5;
int e = a(1,0);
a.show();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dXRpbGl0eT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDxjbGFzcyBUPgpjbGFzcyBNYXRyaXggewoJdmVjdG9yPHZlY3RvcjxUPj4gbTsgCnB1YmxpYzogCiAgICBNYXRyaXggKGludCByLCBpbnQgYykgOiBtKHIsIHZlY3RvcjxpbnQ+KGMsIFQoKSkpIHsgfQogICAgdm9pZCBzaG93KCkgewogICAgCWNvdXQgPDwgIk1hdHJpeCgiPDxtLnNpemUoKTw8IiwiPDxtWzBdLnNpemUoKTw8IikiPDxlbmRsOwogICAgCWZvciAoaW50IGk9MDsgaTxtLnNpemUoKTsgaSsrKSB7CiAgICAJCWNvdXQgPDwiICAiOwogICAgCQlmb3IgKGludCBqPTA7IGo8bVtpXS5zaXplKCk7IGorKykKICAgIAkJICAgIGNvdXQgPDwgbVtpXVtqXTw8IiAiOwogICAgCQljb3V0PDxlbmRsOyAKICAgIAl9CiAgICB9CiAgICB2ZWN0b3I8VD4mIG9wZXJhdG9yW10gKGludCByKSB7IHJldHVybiBtW3JdOyB9CiAgICBUJiBvcGVy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