#include // #include #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ull unsigned long long #define ld long double #define pll pair using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> H >> W; vector power(H + W + 1, 1); for (ll i = 0; i < H + W; ++i) { power.at(i + 1) = power.at(i) * 2 % mod; } vector> A(H, vector(W)); vector> num; for (ll i = 0; i < H; ++i) { for (ll j = 0; j < W; ++j) { cin >> A.at(i).at(j); num.push_back({A.at(i).at(j), i, j}); } } sort(rrng(num)); ll r_num = W, c_num = H; vector row(W, false); vector col(H, false); ll ans = 0; for (ll i = 0; i < num.size(); ++i) { vector n = num.at(i); ll h = n.at(1), w = n.at(2); if (col.at(h) && row.at(w)) { continue; } if (!col.at(h)) { col.at(h) = true; c_num -= 1; } if (!row.at(w)) { row.at(w) = true; r_num -= 1; } ans += (n.at(0) * power.at(r_num) % mod) * power.at(c_num) % mod; ans %= mod; } cout << ans << "\n"; } //0011 //1100 //1100 //0011 //0101 //1010 //1010 //0101