#ifdef ONLINE_JUDGE #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; using mint2 = modint1000000007; #define each(a, ...) for(auto& __VA_ARGS__ : a) #define Each(a, ...) for(auto __VA_ARGS__ : a) #define sz(a) (ll)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template inline bool chmax(T &a, U &&b) { if (a >= (T)b) return false; a = b; return true; } template inline bool chmin(T &a, U &&b) { if (a <= (T)b) return false; a = b; return true; } template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second; } template requires requires(T t) { begin(t); end(t); } && (!is_same_v) istream &operator>>(istream &is, T &v) { for (auto &x : v) is >> x; return is; } template inline void in(T&... a) { (cin >> ... >> a); } template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second; } template requires requires(T t) { begin(t); end(t); } && (!is_same_v) ostream &operator<<(ostream &os, const T &v) { for (auto it = begin(v); it != end(v); it++) os << (it == begin(v) ? "" : " ") << *it; return os; } void out() { cout << '\n'; } template inline void out(T &&a, U&&... b) { cout << a; ((cout << ' ' << b), ...); cout << '\n'; } template inline void print(T&&... a) { (cout << ... << a); } template inline bool yn(bool a, T &&b = "Yes", U &&c = "No") { if (a) out(b); else out(c); return a; } constexpr ll inf = LLONG_MAX >> 2; constexpr array, 4> dxdy4 = {{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}}; constexpr array, 8> dxdy8 = {{{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}}}; void rotate_matrix(vector &A) { if (A.empty()) return; size_t W = A.size(), H = A.front().size(); vector B(H,string(W,0)); for (size_t i = 0; i < H; i++) { for (size_t j = 0; j < W; j++) { B[i][j] = A[j][H - 1 - i]; } } A.swap(B); } void Main() { ll N,M;in(N,M); vector S(N,vector(M));in(S); vector T(N,vector(4,vector(M))); for(ll i=0;iA)->void{ if(i==N){ ll ansi=0; each(A,Ai)ansi+=count(all(Ai),'#'); chmin(ans,ansi); return; } for(ll j=0;j<4;j++){ auto B=A; for(ll x=0;x