#t347. 红与黑

红与黑

Red and Black

Problem Background

Special for beginners, ^_^

Problem Description

There is a rectangular room with its floor tiled by red and black square tiles. You stand on one of the black tiles and can only move to adjacent black tiles. Write a program to compute the total number of black tiles you can reach.

Input Format

The input consists of multiple data sets. The first line of each data set contains two integers WW and HH, the number of tiles in the xx and yy directions, respectively. Both WW and HH do not exceed 2020. The following HH lines each contain WW characters. Each character represents the color of a tile, according to the following rules:

  1. .: a black tile;
  2. #: a white tile;
  3. @: a black tile, and you are standing on it. This character appears exactly once in each data set.

When a line containing two zeros is read, the input ends.

Output Format

For each data set, output one line showing the number of tiles you can reach starting from the initial position (counting the initial tile as well).

Sample Input

6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
0 0

Sample Output

45

Constraints

Time limit: 1s, memory limit: 1024KiB for each test case.