Pair

No attempts yetTime limit2sMemory limit512 MB

Problem

A solitaire board game is played on a rectangular board of m×nm \times n squares. Every square starts out holding either an animal or an obstacle. The character 'X' marks an obstacle, and a digit from '0' to '9' gives the species of the animal in that square.

Two animals can be removed together only when they are of the same species. Once a pair is removed, the two squares become empty and stay empty for the rest of the game. A square holding an obstacle never becomes empty.

A pair can be removed when the two squares are adjacent, or when a path joins them. Two squares are adjacent when they touch side by side, horizontally or vertically. A path is a sequence of adjacent empty squares, and the length of a path is the number of empty squares in it. The two squares holding the animals are not part of the path. When the two squares are adjacent, no path is needed and the length added is 0.

Print the largest number of pairs that can be removed from the board, together with the smallest cumulative path length that reaches that number of pairs.

Input

The first line contains two integers mm and nn separated by a space (1m51 \le m \le 5, 1n51 \le n \le 5).

Each of the next mm lines contains nn characters. Each character is 'X' or a digit from '0' to '9', and there is no space between adjacent characters.

Output

Print two integers on one line, separated by a space. The first is the largest number of pairs that can be removed. The second is the smallest cumulative path length needed to remove that many pairs.