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: from collections import deque
def bfs():
    d = [[False] * w for i in range(h)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]

    que = deque([])
    que.append((sx,sy))
    d[sx][sy] = True
    cnt = 1

    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and Map[nx][ny] != "#" and d[nx][ny] == False:
                cnt += 1
                que.append((nx,ny))
                d[nx][ny] = True
    return cnt

while 1:
    w,h = map(int,input().split())
    if w == 0 and h == 0:
        break
    Map = [str(input()) for i in range(h)]
    for i in range(h):
        for j in range(w):
            if Map[i][j] == "@":
                sx = i
                sy = j
    print(bfs())

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 = []
        for i in range(h):
            if '@'in data[i]:stack= [(i,data[i].index('@'))]
        count = 0
        while len(stack) !=0:
            y,x= stack.pop()
            count +=1
            if y-1 >= 0 and not (y-1,x)in visited and data[y -1][x] == '.':
                visited.append((y-1,x))
                stack.append((y-1,x))
            if x -1 >= 0 and not (y,x-1)in visited and data[y][x-1] == '.':
                visited.append((y,x-1))
                stack.append((y,x-1))
            if y +1 < h and not (y+1,x)in visited and data[y +1][x] == '.':
                visited.append((y+1,x))
                stack.append((y+1,x))
            if x + 1 < w and not (y,x+1)in visited and data[y][x +1] == '.':
                visited.append((y,x+1))
                stack.append((y,x+1))

        print(count)

Python: while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    m = []
    for _ in range(h):
        m.append(list(input()))
    visited = [[False] * w for _ in range(h)]
    dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    answer = 0


    def rec(x, y):
        global answer
        visited[x][y] = True
        answer += 1
        for (dx, dy) in dxy:  # 4方向の移動を試す
            x2 = x + dx
            y2 = y + dy
            if 0 <= x2 < h and 0 <= y2 < w:
                if m[x2][y2] == '.':
                    if not visited[x2][y2]:
                        rec(x2, y2)  # 再帰呼び出し


    for i in range(h):
        for j in range(w):
            if m[i][j] == '@':
                rec(i, j)
                break
        else:
            continue
        break
    print(answer)

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: from queue import *


d = [(1,0),(0,1),(-1,0),(0,-1)]
temp={}

while True:
    W,H = (int(x) for x in input().split())
    mmap=[]
    visited=[]
    flag=0
    count=1
    
    q = Queue()
    
    if W==0 & H==0:
        break
    for i in range(0,H):
        mmap.append(list(input()))
    for i in range (0,H):
        for j in range(0,W):
            if mmap[i][j] == '@':
                start=[i,j]
    
    q.put(start)
    visited.append(list(start))
    while not q.empty():
        now = q.get()
        for myd in d:
            now2 = list(now)
            now2[0] += myd[0]
            now2[1] += myd[1]
            if not(now2[0]==-1 or now2[0]==H or now2[1]==-1 or now2[1]==W) :
                if mmap[now2[0]][now2[1]] != '#' :
                    flag=0
                    for v in visited:
                        if now2 == v :
                            flag=1
                            break
                    if flag==0:
                        count+=1
                        q.put(now2)
                        visited.append(list(now2))
    
    print(count)