#CODEFORCESP7530. President's Office
President's Office
题目描述
贝兰德总统有一个非常宽敞的办公室,除了他之外,还有他的下属在那里工作。每个下属,以及总统本人,都有自己独特颜色的办公桌。每张桌子都是矩形的,其边与办公室的墙壁平行。一天,总统决定成立一个由他所有副手组成的议会。不幸的是,他不记得他的副手的确切数量,但他记得每个副手的办公桌都与他自己的办公桌相邻,也就是说,两张桌子(总统和每个副手的)有一条正长度的公共边。
办公室平面图可以看作一个具有 n 行和 m 列的矩阵。这个矩阵的每个单元格要么为空,要么包含一部分桌子。大写拉丁字母代表每种桌子颜色。字符“句号”(“.”)代表空单元格。
第一行包含两个由空格分隔的整数 n, m (1 ≤ n, m ≤ 100) — 办公室的长度和宽度,以及 c 字符 — 总统办公桌的颜色。接下来的 n 行每行包含 m 个字符 — 办公室描述。保证每张桌子的颜色都是唯一的,并且每张桌子代表给定矩阵的一个连续子矩形。所有颜色都由大写拉丁字母标记。
打印唯一一个数字 — 总统副手的数量。
输入
第一行包含两个由空格分隔的整数 n, m (1 ≤ n, m ≤ 100) — 办公室的长度和宽度,以及 c 字符 — 总统办公桌的颜色。接下来的 n 行每行包含 m 个字符 — 办公室描述。保证每张桌子的颜色都是唯一的,并且每张桌子代表给定矩阵的一个连续子矩形。所有颜色都由大写拉丁字母标记。
输出
打印唯一一个数字 — 总统副手的数量。
Samples
3 4 R
G.B.
.RR.
TTT.
2
3 3 Z
...
.H.
..Z
0
Description
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Print the only number — the amount of President's deputies.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.