#include using namespace std; using ll = long long; using pii = pair; using vi = vector; using vll = vector; using vvi = vector; using vs = vector; using vc = vector; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(a) (a).begin(), (a).end() template using min_pq = priority_queue, greater>; const int INF = 1e9; const ll LINF = 1e18; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vs data(n); rep(i,n) cin >> data[i]; vi wcnt(n,0); vi wt(n,0); ll ans=0; rep(i,n)rep(j,2*n){ if(data[i][j]=='.') { wt[i]+=j-wcnt[i]; ans+=j-wcnt[i]; wcnt[i]++; } } vi mar(n,0); rep(i,n){ mar[i]=wcnt[i]-n; } rep(i,n){ while(mar[i]>0){ rep(j,n){ if(mar[j]<0){ ans+=abs(i-j); ans+=mar[i]-mar[j]-1; mar[j]++; mar[i]--; break; } } } } cout << ans << endl; }