
import java.io.FileNotFoundException;
import java.io.File;
import java.util.Scanner;
import java.io.PrintWriter;

class Dec2 {

	public static void main(String[] args) {

		// Create Scanner to read "maze.txt" and
		// Create PrintWriter to write to "maze2.txt"

		Scanner input = null;
		PrintWriter pw = null;

		try {
			input = new Scanner(new File("maze.txt"));
			pw = new PrintWriter(new File("maze2.txt"));
		} 
		catch (FileNotFoundException e) {
			return;
		}

		input.useDelimiter(",|\n");

		// Read data and store in 2D array

		int numRows = input.nextInt();
		int numCols = input.nextInt();

		char[][] array = new char[numRows][numCols];

		for(int i = 0; i < array.length; i++) {
			for(int j = 0; j < array[i].length; j++) {
				array[i][j] = input.next().charAt(0);
			}
		}

		// Count how many o's in 2D array

		int count = 0;

		for(int i = 0; i < array.length; i++) {
			for(int j = 0; j < array[i].length; j++) {
				if (array[i][j] == 'o'){
					count++;
				}
			}
		}
		System.out.println("Number of o's: " + count);

		// Change all x's in 2D array to spaces

		for(int i = 0; i < array.length; i++) {
			for(int j = 0; j < array[i].length; j++) {
				if(array[i][j] == 'x') {
					array[i][j] = ' ';
				}
			}
		}
	
		// Print 2D array to screen
		printArray(array);
	
		// Print contents of 2D array to "maze2.txt"

		for(char[] row : array) {
			for(char c: row) {
				pw.print(c + " ");
			}
			pw.println();
		}

		pw.close();
	}

	static void printArray(char[][] array) {
		for(char[] row : array) {
			for(char c: row) {
				System.out.print(c + " ");
			}
			System.out.println();
		}
	}


}
