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: 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: def fill(y,x):
    global l,c,w,h
    if 0<=x+1<w and 0<=y<h and l[y][x+1]==".":
        c+=1
        l[y][x+1]=1
        fill(y,x+1)
    if 0<=x-1<w and 0<=y<h and l[y][x-1]==".":
        c+=1
        l[y][x-1]=1
        fill(y,x-1)
    if 0<=x<w and 0<=y+1<h and l[y+1][x]==".":
        c+=1
        l[y+1][x]=1
        fill(y+1,x)
    if 0<=x<w and 0<=y-1<h and l[y-1][x]==".":
        c+=1
        l[y-1][x]=1
        fill(y-1,x)
    return c

while 1:
    w,h=map(int,input().split())
    if not w and not h:break
    l=[list(input()) for _ in range(h)]
    y,x=[[n,i.index("@")] for (n,i) in enumerate(l) if "@" in i][0]
    l[y][x]=1
    c=1
    print(fill(y,x))

Python: while True:
    w,h = map(int,input().split())
    if w == 0:
        break
    around = ''
    for i in range(w + 2):
        around += '#'
    maze = [around]
    cnt = 1
    for i in range(h):
        row = '#' + input() + '#'
        maze.append(row)
        if '@' in row:
            loc = [[i + 1,row.index('@')]]
    maze.append(around)
    visted = loc
    left = True
    while left:
        next_loc = []
        for x,y in loc:
            for i,j in ([1,0],[0,1],[-1,0],[0,-1]):
                if maze[x + i][y + j] == '.' and [x + i,y + j] not in visted:
                    cnt += 1
                    next_loc.append([x + i,y + j])
                    visted.append([x + i,y + j])
            if  next_loc == []:
                print(cnt)
                left = False
                break
        loc = next_loc

Python: def count_area(h,w):
	count = 0
	if (h>0) and (s[h-1][w]== "."):
		s[h-1][w] = "#"
		count += count_area(h-1,w)
	if (h<H-1) and (s[h+1][w]== "."):
		s[h+1][w] = "#"
		count += count_area(h+1,w)
	if (w>0) and (s[h][w-1]== "."):
		s[h][w-1] = "#"
		count += count_area(h,w-1)
	if (w<W-1) and (s[h][w+1]== "."):
		s[h][w+1] = "#"
		count += count_area(h,w+1)
	return count+1

while(True):
	W, H = map(int, input().split())
	if H==0&W==0:break

	s = [list(input()) for i in range(H)]
	
	for h in range(H):
		for w in range(W):
			if s[h][w] == "@":
				s[h][w] = "#"
				print(count_area(h,w))
				break

Python: from collections import deque

y = [-1,0,1,0]
x = [0,-1,0,1]

def main():

    h,w = 0,0
    c = []

    def check(i,j):
        return 0<=i and i<h and 0<=j and j<w

    def bfs(a,b):
        res = 0
        d = deque()
        d.append([a,b])
        f = [[False]*w for _ in range(h)]
        while len(d):
            i,j = d.popleft()
            if not check(i,j):continue
            if c[i][j]=='#':continue
            if f[i][j]==True:continue
            res += 1
            f[i][j]=True
            for k in range(4):
                d.append([i+y[k],j+x[k]])
        return res

    while True:
        w,h = map(int,input().split())
        if h==0 and w==0:break
        c = []
        for i in range(h):
            c.append(input())
        res = 0
        for i in range(h):
            for j in range(w):
                if c[i][j]=='@':
                    res = bfs(i,j)
        print(res)

if __name__ == '__main__':
    main()

Python: from collections import deque

dx,dy = [1,0,-1,0],[0,1,0,-1]

while True:
	w,h = map(int,input().split())
	if w == 0 and h == 0:
		break
	field = [input() for i in range(h)]
	for i in range(h):
		if '@' in field[i]:
			sx,sy = i,field[i].find('@')
	visited = [[False for i in range(w)] for j in range(h)]
	que = deque()
	que.append((sx,sy))
	visited[sx][sy] = True
	while que:
		p = que.popleft()
		for i in range(4):
			nx,ny = p[0] + dx[i],p[1] + dy[i]
			if 0 <= nx < h and 0 <= ny < w and field[nx][ny] != '#' and not visited[nx][ny]:
				visited[nx][ny] = True
				que.append((nx,ny))
	cnt = 0
	for i in range(h):
		for j in range(w):
			cnt += visited[i][j]
	print(cnt)

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

def dfs(s,Map,H,W):
    dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
    for i in range(4):
        Map[s[0]][s[1]] = '*'
        nextPos = (s[0]+dxdy[i][0],s[1]+dxdy[i][1])
        if nextPos[0] >= 0 and nextPos[1] >= 0 and nextPos[0] < H and nextPos[1] < W:
            if Map[nextPos[0]][nextPos[1]] == '.':
                dfs(nextPos,Map,H,W)

while True:
    W,H = map(int,input().split(" "))
    if W == 0 and H == 0:
        break
    Map = [list(input()) for i in range(0,H)]
    for i in range(H):
        for j in range(W):
            if Map[i][j] == '@':
                S = (i,j)

    dfs(S,Map,H,W)
    print(sum([1 if Map[i][j] == '*' else 0 for i in range(H) for j in range(W)]))