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: # coding: utf-8

import sys

def dfs(rw,cm):
    global flag
    flag[rw][cm] = 1
    if 0 <= rw - 1 and mp[rw-1][cm] == '.' and flag[rw-1][cm] == 0:
        dfs(rw-1,cm)
    if cm + 1 < m and mp[rw][cm+1] == '.' and flag[rw][cm+1] == 0:
        dfs(rw,cm+1)
    if 0 <= cm - 1 and mp[rw][cm-1] == '.' and flag[rw][cm-1] == 0:
        dfs(rw,cm-1)
    if rw + 1 < n and mp[rw+1][cm] == '.' and flag[rw+1][cm] == 0:
        dfs(rw+1,cm)

if __name__ == '__main__':
    while 1:
        m,n = map(int,input().split())
        if m == 0 and n == 0:
            break
        mp = []
        for i in range(n):
            mp.append(list(input()))
            if '@' in mp[-1]:
                stj = mp[-1].index('@')
                sti = i
        flag = [[0 for i in range(m)] for j in range(n)]
        dfs(sti,stj)
        print(sum(flag[i].count(1) for i in range(n)))

Python: from collections import deque

while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    else:
        m = []
        d = deque()
        for i in range(h):
            r = input()
            m.append(list(r))
            s = r.find('@')
            if s != -1:
                d.append((s, i))
        while len(d):
            rw, rh = d.popleft()
            m[rh][rw] = 'Y'
            if 0 < rw and m[rh][rw-1] == '.':
                d.append((rw-1, rh))
                m[rh][rw-1] = 'Y'
            if rw < w-1 and m[rh][rw+1] == '.':
                d.append((rw+1, rh))
                m[rh][rw+1] = 'Y'
            if 0 < rh and m[rh-1][rw] == '.':
                d.append((rw, rh-1))
                m[rh-1][rw] = 'Y'
            if rh < h-1 and m[rh+1][rw] == '.':
                d.append((rw, rh+1))
                m[rh+1][rw] = 'Y'
        a = 0
        for i in m:
            a += i.count('Y')
        print(a)

Python: # -*- coding: utf-8 -*-
#rea and blac
h,w=1,1

count=0

def search(x,y):
    #マップの外側か壁の場合は何もしない
    #print(x,y)
    global count
    if x<0 or x>w-1 or y<0 or y>h-1 or map_data[y][x]=='#':
 
        return
        
    
    #以前に到達していたら何もしない
    if reached[y][x]:
         return

    reached[y][x]=1
    count+=1
    #print("aa")



    search(x+1,y)#右
    search(x-1,y)#左
    search(x,y+1)#上
    search(x,y-1)#下
    



while h!=0 and w!=0: 

    count=0
    #グラフの入力方法------

    w,h=map(int ,raw_input().split())
    if h==0 and w==0:
        break

    map_data = [[0]*w for _ in range(h)]
    reached = [[0]*w for _ in range(h)]
    for i in range(h):
        ct = raw_input()
        #print(len(ct))
        for j in range(w):
            map_data[i][j] = ct[j]
            if ct[j]=="@":
                sx=j
                sy=i

    #------



    search(sx,sy)

    print(count)
    count=0
    w=1
    h=1

Python: def floodfill(matrix, x, y):
    global count
    #"hidden" stop clause - not reinvoking for "check" or "#", only for "," or "@".
    if (matrix[x][y] == ".") or (matrix[x][y] == "@"):
        count += 1
        matrix[x][y] = "check"
        #recursively invoke flood fill on all surrounding cells:
        if x > 0:
            floodfill(matrix, x - 1, y)
        if x < len(matrix) - 1:
            floodfill(matrix, x + 1, y)
        if y > 0:
            floodfill(matrix, x, y - 1)
        if y < len(matrix[0]) - 1:
            floodfill(matrix, x, y + 1)
    return count

while True:
    x, y = map(int, input().split())
    if x == y == 0: break
    room = []
    for i in range(y):
        room.append([i for i in input()])

    for key, list in enumerate(room):
        if "@" in list:
            ax, ay = key, list.index("@")

    count = 0
    print(floodfill(room, ax, ay))

Python: def search(x, y, m):
    if x < 0 or y < 0 \
            or 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: # coding: utf-8
def check(p):
    global ans
    global field
    ans+=1
    if(field[p[1]][p[0]]=='.'):
        field[p[1]][p[0]]='#'
    if(0<=p[0]+1<w and field[p[1]][p[0]+1]=='.'):
        check((p[0]+1,p[1]))
    if(0<=p[0]-1<w and field[p[1]][p[0]-1]=='.'):
        check((p[0]-1,p[1]))
    if(0<=p[1]+1<h and field[p[1]+1][p[0]]=='.'):
        check((p[0],p[1]+1))
    if(0<=p[1]-1<h and field[p[1]-1][p[0]]=='.'):
        check((p[0],p[1]-1))
    
    
while 1:
    ans=0
    w,h=map(int,input().split())
    if w==0:
        break
    field=[]
    for i in range(h):
        s=input()
        t=s.find('@')
        if(t!=-1):
            st=(t,i)
        field.append(list(s))
    check(st)
    print(ans)

Python: dxy = [[1,0],[-1,0],[0,1],[0,-1]]
n=0
def rec(x,y):
    global n
    if (x<0 or x>=h or y<0 or y>=w) or (visited[x][y] or tile[x][y]!='.'):
        return 0
    visited[x][y] = True
    n += 1
    for (dx,dy) in dxy:
        x2 = x + dx
        y2 = y + dy
        rec(x2,y2)
    return 0

w,h=map(int,input().split())
ans = []
while((w,h)!=(0,0)):
    n=0
    tile = []
    for _ in range(h):
        tile.append(list(input()))
    visited = [[False] * w for _ in range(h)]
    for a in range(h):
        for b in range(w):
            if(tile[a][b]=='@'):
                pos_x = a
                pos_y = b
                tile[a][b]='.'
    rec(pos_x, pos_y)
    ans.append(n)
    w,h=map(int,input().split())
for a in ans:
    print(a)