import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class No3558 { public static String[][] str; public static boolean[][] tf; public static void main(String[] args) throws IOException{ String[] strings = readStr(); int n = Integer.parseInt(strings[0]); str = new String[n][n*2]; for(int i = 1;i <= n;i++) { str[i-1] = strings[i].split(""); } int count = getXYList2(); System.out.println(count); } public static int getXYList2(){ ArrayList Lary = new ArrayList(); ArrayList Rary = new ArrayList(); Integer[] l,r; int count = 0; int startx = 0; for(int i = 0;i < str.length;i++) { for(int j = 0;j < str.length;j++) { if("#".equals(str[i][j])) { l = new Integer[2]; l[0] = i; l[1] = j; Lary.add(l); } if(".".equals(str[i][j + str.length])) { r = new Integer[2]; r[0] = i; r[1] = j + str.length; Rary.add(r); } if(!Lary.isEmpty() && !Rary.isEmpty()) { l = Lary.removeFirst(); r = Rary.removeFirst(); count += Math.abs(r[0] - l[0]) + Math.abs(r[1] - l[1]); } } } return count; } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }