// Arup Guha
// 8/12/2022
// Solution to 2022 UCF Locals Problem: Aqualin

import java.util.*;

public class aqualin {
	
	final public static int[] DX = {-1,0,0,1};
	final public static int[] DY = {0,-1,1,0};

	public static int n;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		
		// Store two separate grids, one for each team.
		int[][] types = new int[n][n];
		int[][] colors = new int[n][n];
		
		// Read each cell, parse through data. Make my storage 0-based.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				types[i][j] = stdin.next().charAt(0)-'A';
				colors[i][j] = stdin.nextInt()-1;
			}
		}
		
		// Ta da!
		System.out.println(score(types)+" "+score(colors));
	}
	
	public static int score(int[][] grid) {
	
		// This is as big as we have to make this.
		int[] maxfreq = new int[26];
		
		boolean[][] used = new boolean[n][n];
		
		// Try flood-filling from each location.
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
		
				// Been here before.
				if (used[i][j]) continue;
				
				// Fill and get the size of this region.
				int size = go(grid, i, j, used, grid[i][j]);
				
				// Update max.
				maxfreq[grid[i][j]] = Math.max(maxfreq[grid[i][j]], size);
			}
		}
		
		// Add up scores for each biggest component.
		int res = 0;
		for (int i=0; i<26; i++) 
			res += ((maxfreq[i]*(maxfreq[i]-1))/2);
		return res;
	}
	
	// Floodfills from grid[x][y] to adjacent regions that also store item. Updates used array as needed.
	public static int go(int[][] grid, int x, int y, boolean[][] used, int item) {
	
		// Mark it.
		int res = 1;
		used[x][y] = true;
		
		// Try in each direction.
		for (int i=0; i<DX.length; i++) {
			int nX = x + DX[i];
			int nY = y + DY[i];
			
			// Reasons not to include.
			if (!inbounds(nX, nY) || used[nX][nY] || grid[nX][nY] != item) continue;
		
			// Recursively fill.
			res += go(grid, nX, nY, used, item);
		}
		
		// Ta da!
		return res;
	}
	
	// Returns true iff (x,y) is in the grid.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < n;
	}
}