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 collections
while True:
    w,h = map(int,input().split())
    if w==0 and h==0:
        break
    tile=[]
    tile.append(["#"]*(w+2))
    for _ in range(h):
        temp= list(input())
        temp=  ["#"]+ temp + ["#"]
        tile.append(temp)
    tile.append(["#"]*(w+2))

    route=[[[0,0,0,0] for i in range(w)] for j in range(h)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            if tile[i+1][j] ==".":
                route[i-1][j-1][0]= 1
            if tile[i-1][j] ==".":
                route[i-1][j-1][1]= 1
            if tile[i][j+1] ==".":
                route[i-1][j-1][2]= 1
            if tile[i][j-1] ==".":
                route[i-1][j-1][3]= 1
            if tile[i][j]=="@":
                st=[i-1,j-1]

    dir= [[1,0],[-1,0],[0,1],[0,-1]]
    d=[[0]*w for i in range(h)]
    d[st[0]][st[1]]=1
    q= collections.deque()
    q.append(st)
    while len(q)> 0:
        cur = q.popleft()
        for i in range(4):
            if route[cur[0]][cur[1]][i]==1 and d[cur[0]+dir[i][0]][cur[1]+dir[i][1]]==0:
                d[cur[0]+dir[i][0]][cur[1]+dir[i][1]]=1
                q.append([cur[0]+dir[i][0],cur[1]+dir[i][1]])

    ans=0
    for i in range(h):
        for j in range(w):
            if d[i][j] == 1:
                ans+=1
    print(ans)

Python: from queue import Queue

def calcReachableTileNumByBFSearch(room, start_pos):
    q = Queue()
    q.put(start_pos)

    count = 1
    while not q.empty():
        cur_pos = q.get()
        D0 = [1, 0, -1, 0]
        D1 = [0, -1, 0, 1]
        for d in range(4):
            nc = [0,0]
            nc[0] = cur_pos[0]+D0[d]
            nc[1] = cur_pos[1]+D1[d]
            if room[nc[0]][nc[1]] == '.':
                room[nc[0]][nc[1]] = '*'
                q.put([nc[0],nc[1]])
                count +=1
    return count


def solve(width, height):
    room = [['#' for i in range(width+2)] for j in range(height+2)]
    for i in range(height):
        row = input()
        for j in range(width):
            room[i+1][j+1] = row[j]
            if room[i+1][j+1] == '@':
                start = [i+1,j+1]

    return calcReachableTileNumByBFSearch(room, start)


def main():
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        print(solve(width, height))


if __name__ == "__main__":
    main()

Python: from collections import deque

while True:
    W, H = map(int, input().split())
    if W | H == 0:
        break
    tiles = [input() for i in range(H)]
    first = ()
    for h in range(H):
        index = tiles[h].find("@")
        if index != -1:
            first = (index, h)
            break
    memo = {first: 0}
    que = deque([first])
    count = 1
    while len(que) > 0:
        x, y = que.popleft()
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            if (x + dx, y + dy) not in memo:
                if (0 <= x + dx < W) and (0 <= y + dy < H) and tiles[y + dy][x + dx] == ".":
                    count += 1
                    memo[(x + dx, y + dy)] = 1
                    que.append((x + dx, y + dy))
    print(count)

Python: import Queue

while True:
    w, h = [int(_) for _ in raw_input().split()]
    if w == h == 0:
        break
    dat = [list(raw_input()) for _ in xrange(h)]
    queue = Queue.Queue()
    for y, r in enumerate(dat):
        if "@" in r:
            queue.put([r.index("@"), y])

    while not queue.empty():
        x, y = queue.get()
        for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
            if not (0 <= x + dx < w) or not (0 <= y + dy < h):
                continue
            if dat[y + dy][x + dx] == ".":
                dat[y + dy][x + dx] = "@"
                queue.put([x + dx, y + dy])

    ans = 0
    for r in dat:
        ans += r.count("@")

    print(ans)

Python: I=input
def f(x,y,r):
    if not(0<=x<len(r[0])and(0<=y<len(r)))or r[y][x]=='#':return 0
    r[y][x]='#'
    return 1+sum(f(x+dx,y+dy,r)for dx,dy in[[-1,0],[1,0],[0,-1],[0,1]])
while 1:
    w,h=map(int,I().split())
    if w==0:break
    r=[list(input()) for _ in[0]*h]
    for a,b in enumerate(r):
        if '@'in b:y=a;x=b.index('@');break
    print(f(x,y,r))