#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> A, B; string str; int ans = 0; for(int i = 0; i < n; i++){ cin >> str; int cnt = 0; for(int j = 0; j < 2 * n; j++){ if(str[j] == '#') cnt++; else ans += cnt; } sort(str.rbegin(), str.rend()); for(int j = 0; j < n; j++){ if(str[j] == '#') A.emplace_back(i, j); } for(int j = n; j < 2 * n; j++){ if(str[j] == '.') B.emplace_back(i, j); } } for(int i = 0; i < (int)A.size(); i++){ ans += abs(A[i].first - B[i].first) + abs(A[i].second - B[i].second); } cout << ans << '\n'; }