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: dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]
def rec(maze, visited, locat):
  # ４方向全て試す
  for i in dxy:
    n_locat = (locat[0] + i[0], locat[1] + i[1])
    if 0 <= n_locat[0] < len(maze) and 0 <= n_locat[1] < len(maze[0]):
      if maze[n_locat[0]][n_locat[1]] == '.':
        if visited[n_locat[0]][n_locat[1]] == False:
          global count 
          count += 1
          visited[n_locat[0]][n_locat[1]] = True
          rec(maze, visited, n_locat)
  return count
while(True):
  w, h = map(int, input().split())
  if w == 0 and h == 0:
    break
  maze = [[]for i in range(h)]
  visited = [[False for i in range(w)] for j in range(h)]
  for i in range(h):
    mazel = list(input())
    maze[i] = mazel
  count = 1 # @のいちを予めカウントしておく
  for i in range(h):
    for j in range(w):
      if maze[i][j] == '@':
        s = [i, j]
        break
    else:
      continue
    break
  print(rec(maze, visited, s))

Python: import queue

while True :
    w,h = map(int,input().split())
    if w==0 and h ==0 :
        break
    maze = [input() for _ in range(h)]
    visited = [[-1]*w for _ in range(h)]
    for i in range(h):
        if "@"  in  maze[i]:
            x_f = i
    for i in range(w):
        if maze[x_f][i] =="@":
            y_f = i
    visited[x_f][y_f] = 1
    q = queue.Queue()
    q.put([x_f,y_f])
    cnt  = 1
    while  not q.empty():
        x,y = q.get()
        for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
            if 0<= x+dx < h and 0<= y+dy < w:
                if visited[x+dx][y+dy] == -1 and maze[x+dx][y+dy]=='.':
                    cnt += 1
                    visited[x+dx][y+dy] = 1
                    q.put([x+dx,y+dy])
    print(cnt)

Python: def getter(targ,x,y):
    #print(x,y,len(targ[0]),len(targ))
    if 0 > x or x >= len(targ) or 0 > y or y >= len(targ[0]) or targ[x][y] == '#':
        return 0
    else:
        targ[x][y] = '#'
        return 1 + getter(targ,x+1,y) + getter(targ,x-1,y) + getter(targ,x,y+1) + getter(targ,x,y-1)
width,height = [int(n) for n in input().split(" ")]
global lab
while True:
    lab,start = [],[]
    for a in range(height):
        disp = [n for n in input().rstrip('\n')]
        if '@' in disp:
            start.extend([disp.index('@'),a])
        lab.append(disp)
    else:
        a,b = start
        print(getter(lab,b,a))
        width,height = [int(n) for n in input().split(" ")]
        if width == 0 and height == 0:
            break

Python: import sys

sys.setrecursionlimit(10000)


def dfs(x, y):
    global cout
    if 0 <= x < H - 1 and tile[x + 1][y] == ".":
        cout += 1
        tile[x + 1][y] = "#"
        dfs(x + 1, y)
    if 0 < x < H and tile[x - 1][y] == ".":
        cout += 1
        tile[x - 1][y] = "#"
        dfs(x - 1, y)
    if 0 <= y < W - 1 and tile[x][y + 1] == ".":
        cout += 1
        tile[x][y + 1] = "#"
        dfs(x, y + 1)
    if 0 < y < W and tile[x][y - 1] == ".":
        cout += 1
        tile[x][y - 1] = "#"
        dfs(x, y - 1)
    return 0


def search_start():
    for i in range(H):
        for j in range(W):
            if tile[i][j] == "@":
                tile[i][j] = "#"
                return (i, j)


if __name__ == "__main__":
    while True:
        W, H = map(int, input().split())
        if W == 0 and H == 0:
            break
        # print(W, H)
        tile = [list(input()) for _ in range(H)]
        cout = 1
        start = search_start()
        # print(start)
        dfs(start[0], start[1])
        # print(*tile, sep="\n")
        # print("total count : {}".format(cout))
        print(cout)

Python: def search(x, y, m):
    if x >= len(m[0]) or y >= len(m):
        return 0
    if m[y][x] == '#':
        return 0
    m[y][x] = '#'
    return 1 + search(x+1,y, m) + search(x-1,y,m) \
            + search(x,y+1,m) + search(x,y-1,m)

while True:
    w, h = map(int, input().split())
    if w == 0: break
    room = []
    for i in range(h):
        tmp = list(input())
        room.append(tmp[:w])
        if '@' in tmp:
            y = i
            x = tmp.index('@') 
    print(search(x, y, room))

Python: import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Python: c = {"#":0,
     "@":1,
     ".":2,
     "*":3}

d = [[0, -1],
     [0, 1],
     [-1, 0],
     [1, 0]]

output = []
while True:
    w, h = input().split()
    w = int(w)
    h = int(h)

    if w == 0:
        break

    tiles = [[0 for i in range(w)] for j in range(h)]
    for i in range(h):
        row = input()
        for j in range(w):
            tiles[i][j] = c[row[j]]
            if tiles[i][j] == 1:
                queue = [(j, i)]

    count = 1
    while queue:
        x, y = queue[0]
        queue.pop(0)

        for ud, rl in d:
            xt = x+ud
            yt = y+rl
            if xt >= 0 and xt <= w-1 and yt >= 0 and yt <= h-1:
                if tiles[yt][xt] == 2:
                    tiles[yt][xt] = 3
                    count += 1
                    queue.append((xt, yt))

    output.append(count)

for num in output:
    print(num)