#include #include using namespace std; using Mint = atcoder::modint998244353; int main() { int N, M; cin >> N >> M; vector> V; for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) { int t; cin >> t; V.emplace_back(t, i, j + N); } sort(V.rbegin(), V.rend()); atcoder::dsu ufd(M + N); int c = N+M - 2; Mint ans = 0; for (auto [w, i, j] : V) { if (!ufd.same(i, j)) { ufd.merge(i, j); ans += w * (Mint(2).pow(c)); --c; } } cout << ans.val() << endl; }