program main integer n, i, j, ans, temp integer, allocatable, dimension(:) :: c character(2000) s read *, n allocate(c(n)) c = 0 ans = 0 do i = 1, n read *, s do j = 1, 2*n if (s(j:j) == ".") then c(i) = c(i) + 1 ans = ans + j - c(i) end if end do end do do i = 1, n - 1 if (c(i) > n) then do j = 1, n if (i == j .or. c(j) > n - 1) cycle temp = min(n - c(j), c(i) - n) ans = ans + temp * (abs(j - i) - c(j) + c(i) - temp) c(i) = c(i) - temp c(j) = c(j) + temp if (c(i) == n) exit end do end if end do write (6, fmt='(I0)') ans end program main