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: from collections import deque

move = ((0,1),(1,0),(0,-1),(-1,0))

def inmap(x,y):
    if 0 <= x <= Lx-1 and 0<= y <= Ly-1:
        return True
    return False

while True:
    Lx,Ly = map(int,input().split())
    if Lx == 0:
        break
    curx= -1
    cury = -1
    orimap = [[] for _ in range(Ly)]
    for i in range(Ly):
        for j in input():
            orimap[i].append(j)
    for y in range(len(orimap)):
        for x in range(len(orimap[y])):
            if orimap[y][x] == "@":
                curx,cury = x,y
                orimap[y][x]="#"
                break
        if curx != -1:
            break
    Q = deque()
    Q.append([curx,cury])
    count = 1
    while len(Q)>0:
        curx,cury = Q.popleft()
        for dx,dy in move:
            nextx = curx + dx
            nexty = cury + dy
            if inmap(nextx,nexty):
                if orimap[nexty][nextx] != "#":
                    orimap[nexty][nextx] = "#"
                    Q.append([nextx,nexty])
                    count += 1
    print(count)

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections
import itertools


class DepthFirstSearchWithStack(object):

    def __init__(self, width, height, tiles):
        self.width = width
        self.height = height
        self.tiles = tiles
        self.reached = [array.array(
            "B", (False for y in range(height))) for x in range(width)]
        for x, y in itertools.product(range(width), range(height)):
            if tiles[x][y] == "@":
                self.start_tile = (x, y)
                break

    def search(self, x0, y0):
        stack = collections.deque()
        self.reached[x0][y0] = True
        stack.append((x0, y0))
        while stack:
            (x, y) = stack.pop()
            for i, j in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
                if i < 0 or self.width <= i or j < 0 or self.height <= j:
                    pass
                elif self.tiles[i][j] == "#":
                    pass
                elif not self.reached[i][j]:
                    self.reached[i][j] = True
                    stack.append((i, j))

    def count_reachable_tiles(self):
        self.search(*self.start_tile)
        reachable_tiles = sum([self.reached[x][y] for x, y in itertools.product(
            range(self.width), range(self.height))])
        return reachable_tiles


if __name__ == "__main__":
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        else:
            tiles = [x for x in zip(*[input() for y in range(height)])]
            dfs = DepthFirstSearchWithStack(width, height, tiles)
            print(dfs.count_reachable_tiles())

Python: data, res

def valid(x, y):
    global data
    return 0 <= x < W and 0 <= y < H and data[y][x] != '#'

def dfs(x, y):
    global data, res
    if valid(x, y):
        res += 1
        data[y][x] = '#'
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        for i in range(4):
            dfs(x + dx[i], y + dy[i])
    else:
        return
    
while True:
    global data, res
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    data = [list(input()) for _ in range(H)]
    res = 0
    for i in range(W):
        for j in range(H):
            if data[j][i] == '@':
                dfs(i, j)
                break
    print(res)

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



if __name__ == "__main__":
    move_point = 0
    first = True
    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
        if first:
            first = False
        else:
            print('')
        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 collections
while True:
    w,h = map(int,input().split())
    if w == h == 0:
        break
    else:
        ans = 1
        L = []
        q = collections.deque()
        for i in range(h):
            s = input()
            T = []
            for j in range(w):
                if s[j] == '@':
                    T.append(0)
                    q.append([i,j])
                else:
                    T.append(s[j])
            L.append(T)
        dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]
        while len(q) > 0:
            cur = q.popleft()
            for i in range(4):
                y = cur[0]+dy_dx[i][0]
                x = cur[1]+dy_dx[i][1]
                if 0 <= x < w and 0 <= y < h:
                    if L[y][x] == '.':
                        L[y][x] = L[cur[0]][cur[1]]+1
                        ans += 1
                        q.append([y,x])
        print(ans)