// Arup Guha
// 11/16/2015
// Solution to 2015 SER D1 Problem: Checkers

import java.util.*;

public class checkers {

	// Directions for jumping.
	final public static int[] DX = {-2,-2,2,2};
	final public static int[] DY = {-2,2,-2,2};

	public static int n;
	public static char[][] grid;
	public static int whiteCount;

	public static void main(String[] args) {

		// Read in input.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		whiteCount = 0;
		grid = new char[n][];
		for (int i=0; i<n; i++)
			grid[i] = stdin.next().toCharArray();

		// Count all white checkers.
		for (int i=0; i<n*n; i++)
			if (grid[i/n][i%n] == 'W')
				whiteCount++;

		// Just try each black checker, and add to our count.
		int res = 0;
		for (int i=0; i<n; i++)
			for (int j=0; j<n; j++)
				if (grid[i][j] == 'B' && possible(i,j))
					res++;

		// Here is our answer.
		System.out.println(res);
	}

	public static boolean possible(int x, int y) {

		// No white checker can be on a square where this black one can land.
		if (whiteHasMod(x%2,y%2)) return false;

		// Create the graph that is induced by a starting vertex of B and all white checkers as edges.
		ArrayList[] graph = formGraph(x, y);

		// Oops, can't reach all the white checkers.
		if (!connected(graph, x*n+y) || whiteNotCovered(graph)) return false;

		// Now, we just need to check if there is a valid Euler Circuit or Path.
		int degOdd = 0;
		for (int i=0; i<n*n; i++)
			if (graph[i].size()%2 == 1)
				degOdd++;

		// Criteria for Euler Circuit/Path starting at (x,y).
		return degOdd == 0 || (degOdd == 2 && graph[x*n+y].size()%2 == 1);
	}

	public static boolean whiteHasMod(int modX, int modY) {

		// Go through each square, screening white ones to see if any hit the designated mod value for black checkers.
		for (int i=0; i<n; i++)
			for (int j=0; j<n; j++)
				if (grid[i][j] == 'W' && (i%2 == modX || j%2 == modY))
					return true;

		// None hit the value if we get here.
		return false;
	}

	public static ArrayList[] formGraph(int x, int y) {

		// Create space for the edge list.
		ArrayList[] graph = new ArrayList[n*n];
		for (int i=0; i<n*n; i++)
			graph[i] = new ArrayList<Integer>();

		// Go through each square, forming the graph.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {

				// Illegal starting square
				if (i%2 != x%2 || j%2 != y%2) continue;
				if ((i+j)%4 != (x+y)%4) continue;
				if ((i!=x || j!=y) && grid[i][j] != '_') continue;

				// Go all four directions.
				for (int k=0; k<DX.length; k++) {

					// Calculate next spot.
					int nextX = i+DX[k];
					int nextY = j+DY[k];
					if (!inbounds(nextX, nextY)) continue;

					// Square to jump.
					int midX = i+DX[k]/2;
					int midY = j+DY[k]/2;

					// A valid edge starts and ends at valid vertices AND has a mid point of a white checker.
					if ((grid[nextX][nextY] == '_' || (nextX==x && nextY==y)) && grid[midX][midY] == 'W')
						graph[i*n+j].add(nextX*n+nextY);
				}
			}
		}

		// Here it is.
		return graph;
	}

	// Returns true iff we can reach all vertices in graph incident to edges from v.
	public static boolean connected(ArrayList[] graph, int v) {

		// Run our DFS.
		boolean[] used = new boolean[graph.length];
		dfs(graph, v, used);

		// See if there's any vertex that we need to reach that we didn't.
		for (int i=0; i<graph.length; i++)
			if (!used[i] && graph[i].size() > 0)
				return false;

		// If we make it here, we're connected.
		return true;
	}

	// Run a dfs on graph from vertex v.
	public static void dfs(ArrayList[] graph, int v, boolean[] used) {
		used[v] = true;
		for (int i=0; i<graph[v].size(); i++) {
			int next = ((ArrayList<Integer>)graph[v]).get(i);
			if (!used[next])
				dfs(graph, next, used);
		}
	}

	// Just see if the total number of edges is less than the number of white checkers (times 2).
	public static boolean whiteNotCovered(ArrayList[] graph) {
		int total = 0;
		for (int i=0; i<graph.length; i++)
			total += graph[i].size();
		return total < 2*whiteCount;
	}

	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < n;
	}
}
