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 collections

dx = [-1,0,1,0]
dy = [0,-1,0,1]
def movable(dst):
    if dst[0]<0 or dst[0]>b-1:
        return False
    elif dst[1]<0 or dst[1]>a-1:
        return False
    elif MM[dst[0]][dst[1]] == '#':
        return False
    else:
        return True

while True:
    c = 1
    a,b = map(int,input().split())
    if a==0 and b==0:
        exit()
    else:
        MM = []
        for i in range(b):
            q = list(input())
            MM.append(q)
            if '@' in q:
                st = [i, q.index('@')]

        D = [[-1 for _ in range(a)] for _ in range(b)]
        D[st[0]][st[1]] = 0 # 始点への距離は 0, 他の距離は-1
        Q = collections.deque()
        Q.append(st) # 始点
        while len(Q) > 0:
            #print("bfs", Q) # 各ステップでの Q の動作を確認
            cur = Q.popleft()
            for dir in range(4):
                # curからdstに移動可能かつ、dstが未訪問だったら
                dst = [cur[0]+dx[dir], cur[1]+dy[dir]]
                #print(dst)
                if movable(dst) and D[dst[0]][dst[1]] == -1:
                    D[dst[0]][dst[1]] = D[cur[0]][cur[1]]+1
                    c += 1
                    Q.append(dst) # Qにdstを詰める
        print(c)

Python: while True:
    W,H = [int(x) for x in input().split()]
    if W==0 and H==0:
        exit()
    tiles = []
    X = 0
    Y = 0
    for i in range(H):
        tiles.append(input())
        if '@' in tiles[i]:
            Y = i
            X = tiles[i].index('@')
    d = [[9999 for j in range(H*W)] for i in range(H*W)]
    for i in range(H*W):
        d[i][i] = 0
    for i in range(H):
        for j in range(W):
            if j>0:
                if tiles[i][j] in '.@' and tiles[i][j-1] in '.@':
                    d[W*i+j][W*i+j-1] = 1
            if j<W-1:
                if tiles[i][j] in '.@' and tiles[i][j+1] in '.@':
                    d[W*i+j][W*i+j+1] = 1
            if i>0:
                if tiles[i][j] in '.@' and tiles[i-1][j] in '.@':
                    d[W*i+j][W*i+j-W] = 1
            if i<H-1:
                if tiles[i][j] in '.@' and tiles[i+1][j] in '.@':
                    d[W*i+j][W*i+j+W] = 1
    for k in range(H*W):
        for i in range(H*W):
            for j in range(H*W):
                if d[i][j] > d[i][k]+d[k][j]:
                    d[i][j] = d[i][k]+d[k][j]
    cnt = 0
    for i in range(H*W):
        if d[X+Y*W][i]<9999:
            cnt += 1
    print(cnt)

Python: d = [[-1,0],[1,0],[0,-1],[0,1]]
def search(w,h,x,y,m):
    if not(0<=x<w and 0<=y<h) or m[y][x]=='#': return 0
    m[y][x] = '#'
    return sum([search(w,h,x+dx,y+dy,m) for dx,dy in d])+1

while True:
    w,h = map(int,input().split())
    if w==h==0: break
    m = []
    for i,l in enumerate([list(input()) for _ in range(h)]):
        if '@' in l: x,y = l.index('@'),i
        m += [l]
    print(search(w,h,x,y,m))

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 dfs(graph, sx, sy):
    stack = [[sx, sy]]
    visited = []
    cnt = 0
    while stack:
        label = stack.pop(0)
        try:
            g = graph[label[1]][label[0]]
            if (label[0] < 0) or (label[0] > graph[0].__len__() - 1):
                continue
            if (label[1] < 0) or (label[1] >graph.__len__() - 1):
                continue
            if g == '#':
                continue
            if [label[0], label[1]] not in visited:
                # graph[label[1], label[0]] = '#'
                cnt += 1
                visited = [[label[0], label[1]]] + visited
                stack = [[label[0]+1, label[1]], [label[0]-1, label[1]], [label[0], label[1]+1], [label[0], label[1]-1]] + stack
        except IndexError:
            pass
    return cnt


if __name__ == '__main__':
    STR = []
    W, H = [int(i) for i in input().split()]
    while W != 0:
        for j in range(H):
            STR.append(list(input()))
            if '@' in STR[j]:
                sx, sy = STR[j].index('@'), j
        print(dfs(STR, sx, sy))
        STR = []
        W, H = [int(i) for i in input().split()]

Python: from collections import deque
d = [(1,0),(-1,0),(0,1),(0,-1)]
while 1:
    w,h = map(int, input().split())
    if w == h == 0:
        break
    s = [input() for i in range(h)]
    bfs_map = [[1 for i in range(w)] for j in range(h)]
    for y in range(h):
        for x in range(w):
            if s[y][x] == "@":
                ans = 1
                q = deque()
                q.append((y,x))
                bfs_map[y][x] = 0
                while q:
                    y, x = q.popleft()
                    for dy,dx in d:
                        y_ = y+dy
                        x_ = x+dx
                        if 0 <= y_ < h and 0 <= x_ < w:
                            if bfs_map[y_][x_] and s[y_][x_] == ".":
                                ans += 1
                                bfs_map[y_][x_] = 0
                                q.append((y_,x_))
                print(ans)
                break