Sangbeom's Game

Time limit1sMemory limit128 MB

Problem

Sangbeom and Younghoon invented a new game based on chess. It is played on a board with R rows and C columns, and each player controls several chess kings. In a single move, a king steps one square in any of the eight directions: up, down, left, right, and the four diagonals.

Scoring works in an unusual way. A player's score is the sum, over every pair of that player's own kings, of the shortest distance between the two kings. The shortest distance between two kings is the minimum number of moves one king needs to reach the square of the other king; any pieces lying on the path are ignored.

Given the state of the board, compute Sangbeom's score and Younghoon's score.

Input

The first line contains the number of rows R and the number of columns C (1 ≤ R, C ≤ 1,000).

Each of the next R lines contains C characters. The character 'M' is one of Sangbeom's kings, 'S' is one of Younghoon's kings, and '.' is an empty square.

The board contains at least one of Sangbeom's kings and at least one of Younghoon's kings.

Output

Print Sangbeom's score and Younghoon's score on one line, separated by a single space.