#include using namespace std; using pii = pair; using ll = long long; const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f; int n, m, w[N]; char s[1001][2002]; void solve() { scanf("%d", &n); for (int i = 1; i < n + 1; i++) scanf("%s", s[i] + 1); set a, b; for (int i = 1; i < n + 1; i++) { for (int j = 1; j < n * 2 + 1; j++) { if (j <= n && s[i][j] == '#') a.insert({i, j}); if (j > n && s[i][j] == '.') b.insert({i, j}); } } int res = 0; while (a.size() && b.size()) { auto x = *a.begin(), y = *b.begin(); a.erase(a.begin()), b.erase(b.begin()); res += abs(x.first - y.first) + abs(x.second - y.second); } printf("%d\n", res); } int main() { int T = 1; // scanf("%d", &T); while (T--) solve(); return 0; }