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: def Check(A, i, j, W, H) :
    if j-1 >= 0 :
        if A[i][j-1] == "." :
            A[i][j-1] = "+"
            Check(A, i, j-1, W, H)
    if i+1 < H :
        if A[i+1][j] == "." :
            A[i+1][j]= "+"
            Check(A, i+1, j, W, H)
    if j+1 < W :
        if A[i][j+1] == "." :
            A[i][j+1] = "+"
            Check(A, i, j+1, W, H)
    if i-1 >= 0 :
        if A[i-1][j] == "." :
            A[i-1][j] = "+"
            Check(A, i-1, j, W, H)
    return(A)

while True :
    W, H = map(int, input().split())
    if W == 0 and H == 0 :
        break
    
    Tile = [list(input()) for i in range(H)]
    for i in range(H) :
        for j in range(W) :
            if Tile[i][j] == "@" :
                my_i = i
                my_j = j
    Tile[my_i][my_j] = "+"
    Tile_new = Check(Tile, my_i, my_j, W, H)
    count = 0
    for i in range(H) :
        for j in range(W) :
            if Tile_new[i][j] == "+" :
                count += 1
    print(count)

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: #data????§???????[y???][x???]??§??????

if __name__ == "__main__":
    while 1:
        w,h = list(map(int,input().strip().split()))
        if w == h == 0:break
        data = []
        data = []
        for _ in range(h):data.append(list(input()))
        visited = []
        position =(0,0)
        for i in range(h):
            if '@'in data[i]:position = (i,data[i].index('@'))
        stack = []
        count = 0
        stack.append(position)
        while len(stack) !=0:
            position = stack.pop()
            count +=1
            if position[0] -1 >= 0 and not (position[0]-1,position[1])in visited and data[position[0] -1][position[1]] == '.':
                visited.append((position[0] -1,position[1]))
                stack.append((position[0] -1,position[1]))
            if position[1] -1 >= 0 and not (position[0],position[1]-1)in visited and data[position[0]][position[1]-1] == '.':
                visited.append((position[0],position[1]-1))
                stack.append((position[0],position[1]-1))
            if position[0] +1 < h and not (position[0]+1,position[1])in visited and data[position[0] +1][position[1]] == '.':
                visited.append((position[0]+1,position[1]))
                stack.append((position[0]+1,position[1]))
            if position[1] + 1 < w and not (position[0],position[1]+1)in visited and data[position[0]][position[1] +1] == '.':
                visited.append((position[0],position[1] +1))
                stack.append((position[0],position[1]+1))

        print(count)

Python: #!/usr/bin/env python
# conding: utf

from logging import getLogger, StreamHandler, NullHandler, DEBUG, INFO
logger = getLogger(__name__)
#handler = StreamHandler()
handler = NullHandler()
logger.setLevel(DEBUG)
handler.setLevel(DEBUG)
logger.addHandler(handler)
logger.propagate = False

g_field = []
g_count = 0
g_W = -1
g_H = -1

OFFSETS = [(1,0), (-1,0), (0,1), (0,-1)]


if __name__ == "__main__":
    while True:
        g_W, g_H = [int(s) for s in input().strip().split()]

        if g_W == 0 and g_H == 0:
            break
        
        g_field = []
        for _ in range(g_H):
            row = list(input().strip())
            g_field.append(row)
        g_count = 0

        for y in range(g_H):
            for x in range(g_W):
                if g_field[y][x] == "@":
                    start_x = x
                    start_y = y
                    break

        #dfs(start_x, start_y)
        # bfs
        queue = [(start_x, start_y)]
        
        while len(queue) > 0:
            x, y = queue.pop()

            g_count += 1
            g_field[y][x] = "-"

            for dx, dy in OFFSETS:
                logger.debug("diff: {} {}".format(dx, dy))
                new_x = x + dx
                new_y = y + dy

                if new_x < 0 or new_x >= g_W:
                    continue
                if new_y < 0 or new_y >= g_H:
                    continue
                new_tile = g_field[new_y][new_x]
                if new_tile == "#" or new_tile == "-":
                    continue
                if (new_x, new_y) in queue:
                    continue
                
                logger.debug("{}, {}".format(new_x, new_y))
                queue.append((new_x, new_y))

        print(g_count)

Python: from collections import deque

dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]

while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    
    sx = -1
    sy = -1
    mat = [[None for _ in range(W)] for _ in range(H)]
    for i in range(H):
        s = input()
        for j in range(W):
            if s[j] == "@":
                sx = j
                sy = i
            mat[i][j] = s[j]
    
    ans = 0
    q = deque()
    q.append((sx, sy))
    while q:
        (cx, cy) = q.popleft()
        ans += 1
        for dx, dy in dxy:
            nx = cx + dx
            ny = cy + dy
            if 0 <= nx < W and 0 <= ny < H:
                if mat[ny][nx] == ".":
                    mat[ny][nx] = "#"
                    q.append((nx, ny))
    print(ans)