Go: package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

var strByColor = map[Color]string{
	ColorBlack: "black",
	ColorRed:   "red",
}

func (c Color) String() string {
	return strByColor[c]
}

type Node struct {
	ID      int
	X, Y    int
	Color   Color
	NextIDs map[int]struct{}
}

func (n *Node) String() string {
	d, _ := json.Marshal(n)
	return string(d)
}

type Map struct {
	Width, Height int
	Nodes         map[int]*Node
}

func (m *Map) GetByID(id int) *Node {
	return m.Nodes[id]
}

func (m *Map) Get(x, y int) *Node {
	return m.Nodes[m.getID(x, y)]
}

func (m *Map) SetColor(x, y int, c Color) {
	m.Nodes[m.getID(x, y)].Color = c
}

func (m *Map) getID(x, y int) int {
	return x + y*m.Width
}

func (m *Map) init() {
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			id := m.getID(x, y)
			m.Nodes[id] = &Node{ID: id, X: x, Y: y}
		}
	}
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			nextIDs := map[int]struct{}{}
			if x > 1 {
				nextIDs[m.getID(x-1, y)] = struct{}{}
			}
			if x < m.Width {
				nextIDs[m.getID(x+1, y)] = struct{}{}
			}
			if y > 1 {
				nextIDs[m.getID(x, y-1)] = struct{}{}
			}
			if y < m.Height {
				nextIDs[m.getID(x, y+1)] = struct{}{}
			}
			m.Get(x, y).NextIDs = nextIDs
		}
	}
}

func NewMap(w, h int) *Map {
	m := &Map{Width: w, Height: h, Nodes: map[int]*Node{}}
	m.init()
	return m
}

type Searcher struct {
	Map        *Map
	queue      []*Node
	touchedIDs map[int]struct{}
	visitedIDs map[int]struct{}
}

func NewSearcher(m *Map) *Searcher {
	return &Searcher{
		Map:        m,
		queue:      []*Node{},
		touchedIDs: map[int]struct{}{},
		visitedIDs: map[int]struct{}{},
	}
}

func (s *Searcher) Search(start *Node) {
	s.enqueue(start)

	for {
		if len(s.queue) == 0 {
			break
		}
		for nextID := range s.dequeue().NextIDs {
			n := s.Map.GetByID(nextID)
			if n.Color == ColorRed || s.hasTouched(n) {
				continue
			}
			s.enqueue(n)
		}
	}
}

func (s *Searcher) VisitedNodeCount() int {
	return len(s.visitedIDs)
}

func (s *Searcher) hasTouched(n *Node) bool {
	_, ok := s.touchedIDs[n.ID]
	return ok
}

func (s *Searcher) enqueue(n *Node) {
	s.queue = append(s.queue, n)
	s.touchedIDs[n.ID] = struct{}{}
}

func (s *Searcher) dequeue() *Node {
	n := s.queue[0]
	s.queue = s.queue[1:]
	s.visitedIDs[n.ID] = struct{}{}
	return n
}

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])

		m := NewMap(w, h)

		// Set colors
		var start *Node
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					m.SetColor(i+1, y, ColorBlack)
					if c == '@' {
						start = m.Get(i+1, y)
					}
				case '#':
					m.SetColor(i+1, y, ColorRed)
				}
			}
		}

		// Search
		s := NewSearcher(m)
		s.Search(start)
		fmt.Println(s.VisitedNodeCount())
	}
}

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()