#include #include using namespace std; using i32 = int; using i64 = long long; using i128 = __int128_t; using f64 = double; using p2 = pair; using p3 = tuple; using mint = atcoder::modint998244353; constexpr i64 inf = 1e18; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } void _main() { i64 n; cin >> n; vector s(n); i64 ans = 0; vector cnt(n); for (i64 i = 0; i < n; i++) { cin >> s[i]; i64 c = 0; for (i64 j = 0; j < 2 * n; j++) { if (s[i][j] == '#') { c++; continue; } if (j - c >= n) ans += j - n + 1; else ans += c; cnt[i]++; } } for (i64 i = 0; i < n; i++) { for (i64 j = 0; j < n; j++) { while (cnt[i] > n && cnt[j] < n) { ans += abs(j - i) + (n - cnt[j] - 1); cnt[i]--, cnt[j]++; } } } cout << ans << "\n"; }