Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

type Node struct {
	ID    int
	X, Y  int
	Color Color
	Nexts []*Node
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		// Initialize map
		m := map[int]map[int]*Node{}
		for x := 1; x <= w; x++ {
			m[x] = map[int]*Node{}
			for y := 1; y <= h; y++ {
				m[x][y] = &Node{ID: x + y*w, X: x, Y: y}
			}
		}
		for x := 1; x <= w; x++ {
			for y := 1; y <= h; y++ {
				nexts := []*Node{}
				if n, ok := m[x-1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y-1]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x+1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y+1]; ok {
					nexts = append(nexts, n)
				}
				m[x][y].Nexts = nexts
			}
		}

		// Set colors
		queue := []*Node{}
		touchedIDs := map[int]struct{}{}
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					n := m[i+1][y]
					n.Color = ColorBlack
					if c == '@' {
						queue = append(queue, n)
						touchedIDs[n.ID] = struct{}{}
					}
				case '#':
					m[i+1][y].Color = ColorRed
				}
			}
		}

		// Search
		visitedIDs := map[int]struct{}{}
		for {
			if len(queue) == 0 {
				break
			}
			n := queue[0]
			queue = queue[1:]
			visitedIDs[n.ID] = struct{}{}
			for _, next := range n.Nexts {
				if next.Color == ColorRed {
					continue
				}
				if _, ok := touchedIDs[next.ID]; !ok {
					queue = append(queue, next)
					touchedIDs[n.ID] = struct{}{}
				}
			}
		}
		fmt.Println(len(visitedIDs))
	}
}

Python: def depth_first_search(x, y):
    """
    ??±???????????¢?´¢?????????
    :param x: ?????¨??°????¨?
    :param y: ?????¨??°??????
    :return: ?????°
    """

    # ????????????????????§?¢??????????
    # ??????x  ,y+1
    # ??????x+1,y
    # ??????x  ,y-1
    # ??????x-1,y
    move_list = [[0,1],[1,0],[0,-1],[-1,0]]
    for i in range(0,4,1):
        next_x = x+move_list[i][0]
        next_y = y+move_list[i][1]
        # tile_map??????????§??????§????????´??????'.'???
        if 0 <= next_x and 0 <= next_y and \
            next_x < W and next_y < H and \
            tile_map[next_y][next_x] != '#':

            # ?§?????????????????????¨??°????§??????§??????????????????"#"??????????????????
            tile_map[y][x] = '#'
            import __main__
            __main__.move_point = __main__.move_point+1
            depth_first_search(next_x, next_y)

def get_start_point(tile_map):
    """
    @????????????????????????
    :param tile_map:
    :return:
    """
    for i, y in enumerate(tile_map):
        for j, x in enumerate(y):
            if x == '@':
                return i, j

def check_testcase():
    with open('./1130-input.txt') as f:
        pre_input_testcase = f.read()
    with open('./1130-output.txt') as f:
        pre_output_testcase = f.read()
    pre_input_testcase = pre_input_testcase.splitlines()
    output_testcase = pre_output_testcase.splitlines()

    test_tile_size = [0]*len(output_testcase)
    test_tile_map = [[""]]*len(output_testcase)
    map_info_cnt = 0
    map_info_index = 0
    for v in pre_input_testcase:
        if map_info_cnt == 0:
            W, H = [int(x) for x in v.split(' ')]
            test_tile_size.append([W, H])
            map_info_cnt = H
            map_info_index = map_info_index+1
        else:
            print(map_info_index)
            test_tile_map[map_info_index]=test_tile_map[map_info_index].append(v)
            map_info_cnt = map_info_cnt -1
    import ipdb;ipdb.set_trace()

if __name__ == "__main__":
    move_point = 0
    while (True):
        # input_1 : tile????????????
        tile_size = input('').split(' ')
        W, H = [int(x) for x in tile_size]
        if W == 0 and H == 0:
            break
        tile_map=[''] * H
        for i in range(0, H, 1):
            # input_2 : tile???????????????????????????
            map_line = list(input(''))
            tile_map[i] = map_line
        start_H, start_W = get_start_point(tile_map)
        depth_first_search(start_W, start_H)
        print(move_point)

Python: import copy
w, h = map(int,input().split())
while [h, w] != [0, 0]:
    area = []
    a = 1
    for i in range(h):
        area.append(list(input()))
        area[i].insert(0,"#")
        area[i].append("#")
    area.insert(0,["#" for i in range(w + 2)])
    area.append(["#" for i in range(w + 2)])

    que = []
    for i in range(h):
        for j in range(1, w + 1):
            if area[i][j] == "@":
                que.append([i, j])
                break
        else:
            continue
        break
    while True:
        nque = []
        for i in que:
            h1 = i[0]
            w1 = i[1]
            if area[h1 - 1][w1] == ".":
                area[h1 - 1][w1] = "*"
                nque.append([h1 - 1, w1])
                a += 1
            if area[h1 + 1][w1] == ".":
                area[h1 + 1][w1] = "*"
                nque.append([h1 + 1, w1])
                a += 1
            if area[h1][w1 - 1] == ".":
                area[h1][w1 - 1] = "*"
                nque.append([h1, w1 - 1])
                a += 1
            if area[h1][w1 + 1] == ".":
                area[h1][w1 + 1] = "*"
                nque.append([h1, w1 + 1])
                a += 1
        if nque == []:
            break
        que = copy.deepcopy(nque)

    print(a)
        
    w, h = map(int,input().split())

Python: mx = [0, 1, 0, -1]
my = [-1, 0, 1, 0]

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    tiles = [[i for i in input()] for j in range(h)]
    ax = ay = 0
    for i in range(h):
        for j in range(w):
            if tiles[i][j] == '@':
                ax, ay = j, i
    que = [(ax, ay)]
    tiles[ay][ax] = '#'
    cnt = 1

    while 0 < len(que):
        new_que = []
        for x, y in que:
            for i in range(4):
                nx, ny = x + mx[i], y + my[i]
                if 0 <= nx <= w - 1 and 0 <= ny <= h - 1:
                    if tiles[ny][nx] == '.':
                        cnt += 1
                        new_que.append((nx, ny))
                        tiles[ny][nx] = '#'
        que = new_que
    print(cnt)

Python: w,h=map(int,input().split())
while w!=0 or h!=0:
    maps=[]
    flag=False
    ans=0
    for i in range(h):
        k=list(input())
        maps.append(k)
    for i in range(h):
        if flag:
            break
        for j in range(w):
            if maps[i][j]=='@':
                maps[i][j]='#'
                pos_x=i
                pos_y=j
                flag=True
                break
    def check(x,y):
        global maps
        if 0<=x<h and 0<=y<w:
            pass
        else:
            return False
        if maps[x][y]=='#':
            return False
        else:
            return True
    def bfs(x,y):
        global ans
        global maps
        for i in [[0,1],[0,-1],[1,0],[-1,0]]:
            p=i[0]
            q=i[1]
            if check(x+p,y+q):
                ans+=1
                maps[x+p][y+q]='#'
                bfs(x+p,y+q)
    bfs(pos_x,pos_y)
    print(ans+1)
    w,h=map(int,input().split())