fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let grid = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.chars().collect::>() }) .collect::>(); let mut result = 0usize; if !(0..n).any(|i| grid[0][i] == '#' || grid[n-1][i] == '#' || grid[i][0] == '#' || grid[i][n-1] == '#') { result = 4; } for dir in 0..2 { for is_w in 0..2 { let mut grid = grid.clone(); let mut temp = 0usize; if is_w == 1 { for i in 0..n { let cnt = (0..n).filter(|&j| grid[i][j] == '#').count(); if cnt > 1 { continue; } if dir == 0 { if cnt == 0 || grid[i][0] == '#' { (1..n).for_each(|j| grid[i][j] = '#'); temp += 1; } else if grid[i][n-1] == '#' { (0..n-1).for_each(|j| grid[i][j] = '#'); temp += 1; } } else { if cnt == 0 || grid[i][n-1] == '#' { (0..n-1).for_each(|j| grid[i][j] = '#'); temp += 1; } else if grid[i][0] == '#' { (1..n).for_each(|j| grid[i][j] = '#'); temp += 1; } } } let j = if dir == 0 { 0 } else { n-1 }; let cnt = (0..n).filter(|&i| grid[i][j] == '#').count(); if cnt == 0 { temp += 1; } else if cnt == 1 && (grid[0][j] == '#' || grid[n-1][j] == '#') { temp += 1; } } else { for j in 0..n { let cnt = (0..n).filter(|&i| grid[i][j] == '#').count(); if cnt > 1 { continue; } if dir == 0 { if cnt == 0 || grid[0][j] == '#' { (1..n).for_each(|i| grid[i][j] = '#'); temp += 1; } else if grid[n-1][j] == '#' { (0..n-1).for_each(|i| grid[i][j] = '#'); temp += 1; } } else { if cnt == 0 || grid[n-1][j] == '#' { (0..n-1).for_each(|i| grid[i][j] = '#'); temp += 1; } else if grid[0][j] == '#' { (1..n).for_each(|i| grid[i][j] = '#'); temp += 1; } } } let i = if dir == 0 { 0 } else { n-1 }; let cnt = (0..n).filter(|&j| grid[i][j] == '#').count(); if cnt == 0 { temp += 1; } else if cnt == 1 && (grid[i][0] == '#' || grid[i][n-1] == '#') { temp += 1; } } result = result.max(temp); } } println!("{}", result); }