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: (lambda f: f(f))(lambda this, atin=lambda line, yp, ri=lambda l: room.append([{xi: x} for xi, x in enumerate(l)]): [point.__setitem__("x", line.index("@")), point.__setitem__("y", yp), ri(line)] if "@" in line else ri(line), search=lambda xpoint, ypoint, srch, now: [room[ypoint][xpoint].__setitem__(xpoint, "@"), srch(xpoint - 1, ypoint, srch, now) + srch(xpoint + 1, ypoint, srch, now) + srch(xpoint, ypoint + 1, srch, now) + srch(xpoint, ypoint - 1, srch, now) + 1][1] if 0 <= xpoint < wh[0] and 0 <= ypoint < wh[1] and now(xpoint, ypoint) else 0, now=lambda xpoint, ypoint: room[ypoint][xpoint].get(xpoint) is ".": [globals().__setitem__("wh", list(map(int, input().split()))), globals().__setitem__("room", []), globals().__setitem__("point", {"x": None, "y": None}), [atin(input(), ypoint) for ypoint in range(wh[1])], [room[point["y"]][point["x"]].__setitem__(point["x"], "."), print(search(point["x"], point["y"], search, now)), this(this)] if room else None])

Python: def main():
    while 1:
        w, h = map(int, input().split())
        if w == 0: break
        fld = [[] for i in range(h)]
        for i in range(h):
            readline = input()
            for j in range(w):
                item = readline[j]
                fld[i].append(item)
                if item == '@': sy, sx = i, j
        solve(fld, sy, sx)
        count = 0
        for i in range(h):
            for j in range(w):
                if fld[i][j] == 'A': count += 1
        print(count)

def solve(fld, cy, cx):
    vy = [1,-1,0,0]
    vx = [0,0,1,-1]
    fld[cy][cx] = 'A'
    for i in range(4):
        ny = cy + vy[i]
        nx = cx + vx[i]
        if ny < 0 or nx < 0 or ny >= len(fld) or nx >= len(fld[0]):continue
        elif fld[ny][nx] == '.': solve(fld, ny, nx)
main()

Python: from collections import deque

ans = []
while True:
    w, h = map(int, input().split())
    if not w and not h:
        break
    
    roadmap = []
    d = deque()
    able = [[False for i in range(w)] for j in range(h)]
    for i in range(h):
        roadmap.append(input())
        
    
    for i in range(h):
        for j in range(w):
            if roadmap[i][j] == '@':
                able[i][j] = True
                d.append([i, j])

    
    while len(d):
        y, x = d.pop()
        
        for course in [[0, 1], [1, 0], [-1, 0], [0, -1]]:
            tmpy, tmpx = y + course[0], x + course[1]
            if tmpy < 0 or tmpy >= h or tmpx < 0 or tmpx >= w:
                continue
                
            if not able[tmpy][tmpx] and roadmap[tmpy][tmpx] == '.':
                able[tmpy][tmpx] = True
                d.append([tmpy, tmpx])

    a = 0
    for i in range(h):
        a += len(list(filter(lambda x:x, able[i])))

    ans.append(a)

[print(i) for i in ans]

Python: move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
from collections import deque
def main(w, h):
    field = [list(input()) for i in range(h)]
    check = [[True] * w for i in range(h)]
    q = deque()
    for i in range(h):
        for k in range(w):
            if field[i][k] == "@":
                q.append((k, i))
                check[i][k] = False
    ans = 1
    while q:
        x, y = q.popleft()
        for mx, my in move:
            xm = mx + x
            ym = my + y
            if 0 <= xm < w and 0 <= ym < h:
                if field[ym][xm] == "." and check[ym][xm]:
                    check[ym][xm] = False
                    q.append((xm, ym))
                    ans += 1
    print(ans)
while 1:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    main(w,h)

Python: from collections import deque
while 1:
    W,H = map(int,input().split())
    if W==0 and H==0:break
    tizu = []
    for i in range(H):
        row = input()
        if "@" in row:
            start = (i,row.index("@"))#h,w の順
        tizu.append(row)
    went = [[False]*W for i in range(H)]
    went[start[0]][start[1]] = True
    ans = 1
    queue = deque()#append,popleft
    queue.append(start)
    while queue:
        curh,curw = queue.popleft()
        for dh,dw in ((0,1),(0,-1),(1,0),(-1,0)):
            newh = curh + dh
            neww = curw + dw
            if 0<=newh<H and 0<=neww<W:
                if tizu[newh][neww] == "." and not went[newh][neww]:
                    went[newh][neww] =True
                    queue.append((newh,neww))
                    ans += 1
    print(ans)

Python: import queue
dxy=[(1,0),(0,1),(-1,0),(0,-1)]
def bfs(sx,sy,H,W):#幅優先探索
    q=queue.Queue()
    visited=[[False]*W for _ in range(H)]
    q.put((sx,sy))
    visited[sx][sy]=True
    ans=1
    while not q.empty():
        px,py=q.get()
        for dx,dy in dxy:
            nx=px+dx
            ny=py+dy
            if 0<=nx<H and 0<=ny<W:
                if c[nx][ny]=='.' and visited[nx][ny]==False:
                    visited[nx][ny]=True
                    q.put((nx,ny))
                    ans+=1
    return ans
while True:
    W,H=map(int,input().split())
    if(W==0 and H==0):
        break
    c=[input() for _ in range(H)]
    for i in range(H):
        if "@" in c[i]:
            sx=i
            sy=c[i].index("@")
    print(bfs(sx,sy,H,W))

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