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: W,H=(int(i) for i in input().split())
while W!=0 or H!=0:
    a=[]
    T=[]
    for i in range(H):
        T.append(input())
        a.append([])
        for j in range(W):
            a[i].append(0)
 #   print(T[0][0])
    i=0
    j=0
    while T[i][j]!="@":
        j=0
        while j<W and T[i][j]!="@":
            j+=1
    #        print(j)
        if j>=W:
            j-=1
        if T[i][j]!="@":
            i+=1
  #      print(i)
    s=[[i,j]]
    a[i][j]=1
    c=1
    while s!=[]:
        u=[]
        for l in range(len(s)):
            i=s[l][0]
            j=s[l][1]
            i-=1
            k=0
            while k<2:
            #    print(j)
                if 0<=i<H and a[i][j]==0 and T[i][j]==".":
                    a[i][j]=1
                    u.append([i,j])
                    c+=1
                i+=2
                k+=1
            i-=3
            j-=1
            k=0
            while k<2:
                if 0<=j<W and a[i][j]==0 and T[i][j]==".":
                    a[i][j]=1 
                    u.append([i,j])
                    c+=1
                j+=2
                k+=1
        s=u
    #    print (a)
    print(c)
    W,H=(int(i) for i in input().split())

Python: anslist = []
def sarch(i, j, visited):

    if 0 < i:
        if visited[i - 1][j] == 0:
            visited[i - 1][j] = 1
            sarch(i - 1, j, visited)
    if i < len(visited) - 1:
        if visited[i + 1][j] == 0:
            visited[i + 1][j] = 1
            sarch(i + 1, j, visited)
    if 0 < j:
        if visited[i][j - 1] == 0:
            visited[i][j - 1] = 1
            sarch(i, j - 1, visited)
    if j < len(visited[0]) - 1:
        if visited[i][j + 1] == 0:
            visited[i][j + 1] = 1
            sarch(i, j + 1, visited)
    return visited


while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    grid = [list(input()) for i in range(h)]
    visited = [[0 for i in range(w)] for j in range(h)]
    starti = 0
    startj = 0
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "@":
                starti = i
                startj = j
                visited[i][j] = 1
            elif grid[i][j] == "#":
                visited[i][j] = -1
            else:
                visited[i][j] = 0

    visited = sarch(starti, startj, visited)
    #print(visited)
    ans = 0
    for i in visited:
        for j in i:
            if j == 1:
                ans += 1
    anslist.append(ans)

for i in anslist:
    print(i)

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:
            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: data, res

def valid(x, y):
    global data
    return 0 <= x < W and 0 <= y < H and data[y][x] != '#'

def dfs(x, y):
    global data, res
    if valid(x, y):
        res += 1
        data[y][x] = '#'
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        for i in range(4):
            dfs(x + dx[i], y + dy[i])
    else:
        return
    
while True:
    global data, res
    W, H = map(int, input().split())
    if not W:
        break
    data = [list(input()) for _ in range(H)]
    res = 0
    for i in range(W):
        for j in range(H):
            if data[j][i] == '@':
                dfs(i, j)
                break
    print(res)

Python: import copy
w, h = map(int,input().split())
while [h, w] != [0, 0]:
    area = []
    a = 1
    for i in range(h):
        area.append(list(input()))
        area[i].insert(0,"#")
        area[i].append("#")
    area.insert(0,["#" for i in range(w + 2)])
    area.append(["#" for i in range(w + 2)])

    que = []
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if area[i][j] == "@":
                que.append([i, j])
                break
        else:
            continue
        break
    while True:
        nque = []
        for i in que:
            h1 = i[0]
            w1 = i[1]
            if area[h1 - 1][w1] == ".":
                area[h1 - 1][w1] = "*"
                nque.append([h1 - 1, w1])
                a += 1
            if area[h1 + 1][w1] == ".":
                area[h1 + 1][w1] = "*"
                nque.append([h1 + 1, w1])
                a += 1
            if area[h1][w1 - 1] == ".":
                area[h1][w1 - 1] = "*"
                nque.append([h1, w1 - 1])
                a += 1
            if area[h1][w1 + 1] == ".":
                area[h1][w1 + 1] = "*"
                nque.append([h1, w1 + 1])
                a += 1
        if nque == []:
            break
        que = copy.deepcopy(nque)

    print(a)
        
    w, h = map(int,input().split())