题目描述
Problem Background
yyy2015c01 quickly solved the problem and received praise from the neighbors. Happy to return home, she gave the candy to her mother, enjoyed a delicious lunch, and then took a sweet nap, feeling life was truly wonderful. In the afternoon, her father came home and, having heard about yyy2015c01's help to the teacher and neighbors, decided to take her to the amusement park to play on her favorite dance machine as a reward. yyy2015c01 was thrilled and jumped three feet high with excitement.
Problem Description
The amusement park was bustling with people, and every dance machine was surrounded by crowds. How to get through this? With so many people, it seemed like it would take a long time to play. yyy2015c01 looked around and suddenly spotted a dance machine with no one in front of it. "Ha, I found one without people, quickly go..." However, upon reaching it, she discovered that the new machine's玩法 was different. The grid below her feet displayed many Xs in random positions. Stepping on a grid required calculating its corresponding perimeter according to the rules and then inputting the correct perimeter into the machine. The final winner could even get a free game ticket from the amusement park. yyy2015c01 was tempted. Can you help yyy2015c01 successfully get the game ticket?
The rules of the game are as follows:
The new dance machine pad has many targets to analyze, determined by stepping on a target. The perimeter of the target boundary is a useful measurement parameter. Programming task: determine the perimeter of the selected target. The dance machine pad is a rectangular grid, with points . indicating empty spaces and uppercase letters X indicating parts of the target.
An X in the grid refers to a complete square grid area, including its boundary and the target itself. An X at the center of the grid is adjacent to Xs in all eight directions. Any two adjacent Xs have overlapping square grid areas at their boundaries or corners, so their square grid areas are adjacent. A target is composed of a series of adjacent X square grid areas connected together. In grid 1, a target fills the entire grid; in grid 2, there are two targets, one of which occupies only the bottom-left square grid area, and the rest of the Xs belong to another target.
yyy2015c01 always steps on an X to select the target containing that X, recording the coordinates of the step. The row and column numbers start from the top left corner, numbered from 1. A useful statistical parameter is the perimeter of the target. Assume each side of an X has a square unit.
The target will not contain any completely enclosed holes.
Input Format
There are $M+1$ lines in total. The first line contains four positive integers $M, N, X, Y$ (separated by spaces), indicating the grid size is $M$ rows and $N$ columns, and the grid at the $X$-th row and $Y$-th column was stepped on. The following $M$ lines consist of characters . and X.
Output Format
There is one line in total, indicating the perimeter of the selected target.
Sample Input and Output
Sample Input #1
2 2 2 2
XX
XX
Sample Output #1
8
Sample Input #2
6 4 2 3
.XXX
.XXX
.XXX
...X
..X.
X...
Sample Output #2
18
Notes
$1 \leq M \leq 20$, $1 \leq N \leq 20$, $1 \leq X \leq M$, $1 \leq Y \leq N$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分