Freedom Fighter

Bangladesh became independent in 16-th December 1971 after more than two decades of struggle and with a nine month long war. This war is often referred to as the Liberation War. During the liberation war Bangladesh was divided into 11 sectors. Every sector was under the control of a sector commander who directed the freedom fighter. Most of the sector also had some opponent soldiers. In that time, the sector commander faced a serious problem. They were not being able to count accurately how many freedom fighters and opponent groups were there in each sector and also how many groups are still in fighting. According to this information all sector commander will make a decision about their future planning. They took the help of a programmer during that time. The programmer solved the problem and played a vital role in proper planning of the war. 32 years have passed since the glorious Liberation War of Bangladesh. As a programmer, you are committed to find again a way of solving the problem. In the figure the area bordered by a rectangle indicates a sector. In the input to your program a sector may contain any of the three characters ‘’, ‘B’, ‘P’. Here ‘B’ indicates the locations where there are some freedom fighters, ‘P’ indicates the places occupied by enemy forces and the locations occupied by none of them are identified by some ‘’. In a sector all the ‘B’, ‘P’ or ‘’ are connected either horizontally or vertically. Within a sector there may be one or more freedom fighter group or enemy group. Each of the freedom fighter groups will be identified by some ‘B’ connected to another vertically or horizontally. Similarly enemy groups will be identified by the character ‘P’. No two sectors will have a connection either horizontally or vertically. There may be some ‘.’ (dots) to separate two sectors. In the above picture we can see that there are two (2) groups in a sector. If a group is horizontally or vertically connected to an opponent group then this two groups are said to be in fighting position. It is granted that a freedom fighter group can fight only one opponent group at a time. Input There will be several test cases. The input of each test case starts with a single integer n (5 ≤ n ≤ 50). A ‘0’ for the value of n indicates the end of input. The next n lines consist of a description of n × n grid.Eachlinewillhavencharacterswhichwillbeeitherof‘.’,‘’,‘B’and‘P’.

2/2 Output For each set of input, output as many lines as the number of sectors detailing the number of freedom fighter groups and enemy groups. The last line of the input will indicate how many groups are in fighting position. The sectors are numbered according to the position of the top left corner in row major order. Print a blank line after each test case. For exact format of input and output see the sample output below. Sample Input 16 ................ ................ .......... .PP...... .....B.. ....... .BB......... .......... ................ .....*.... ....*BBBB... ....BBPP... ....**... ....PP... ......... ................ 0 Sample Output Sector #1: contain 1 freedom fighter group(s) & 1 enemy group(s) Sector #2: contain 1 freedom fighter group(s) & 0 enemy group(s) Sector #3: contain 2 freedom fighter group(s) & 2 enemy group(s) Total 2 group(s) are in fighting position.