Buggy python submission (verdict: Runtime Error):
def search(M, l, walkable):
    i, j = (l.pop(0))
    nexts = []
    if i !=0:
        nexts.append((i-1, j))
    if i != len(M)-1:
        nexts.append((i+1, j))
    if j != 0:
        nexts.append((i, j-1))
    if j != len(M[0])-1:
        nexts.append((i, j+1))

    for nex in nexts:
        x, y = nex
        if M[x][y] == '.' and not nex in walkable:
            l.append(nex)
            walkable.append(nex)

inp = ''
while '0 0' != (inp = input()):
    i, j = [int(x) for x in inp.split()]
    M = []
    l = []
    for n in range(j):
        M.append(input())
        if '@' in M[n]:
            l.append((n, M[n].find('@')))

    walkable = []
    while l:
        search(M, l, walkable)
    print(len(walkable))

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Buggy python submission (verdict: Runtime Error):
def search(M, l, walkable):
    i, j = (l.pop(0))
    nexts = []
    if i !=0:
        nexts.append((i-1, j))
    if i != len(M)-1:
        nexts.append((i+1, j))
    if j != 0:
        nexts.append((i, j-1))
    if j != len(M[0])-1:
        nexts.append((i, j+1))

    for nex in nexts:
        x, y = nex
        if M[x][y] == '.' and not nex in walkable:
            l.append(nex)
            walkable.append(nex)

inp = ''
while '0 0' != (inp = input()):
    i, j = [int(x) for x in inp.split()]
    M = [input() for i in range(j)]
    l = []
    for n in len(M):
        if '@' in M[n]:
            l.append((n, M[n].find('@')))

    walkable = []
    while l:
        search(M, l, walkable)
    print(len(walkable)+1)

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Buggy python submission (verdict: Runtime Error):
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print solve(w,h)

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Buggy python submission (verdict: Runtime Error):
def search(M, l, walkable):
    i, j = (l.pop(0))
    nexts = []
    if i !=0:
        nexts.append((i-1, j))
    if i != len(M)-1:
        nexts.append((i+1, j))
    if j != 0:
        nexts.append((i, j-1))
    if j != len(M[0])-1:
        nexts.append((i, j+1))

    for nex in nexts:
        x, y = nex
        if M[x][y] == '.' and not nex in walkable:
            l.append(nex)
            walkable.append(nex)

inp = ''
while '0 0' != (inp = input()):
    i, j = [int(x) for x in inp.split()]
    M = [input() for i in range(j)]
    l = []
    for n in len(M):
        if '@' in M[n]:
            l.append((n, M[n].find('@')))

    walkable = []
    while l:
        search(M, l, walkable)
    print(len(walkable)+1)

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Buggy python submission (verdict: Runtime Error):
def search(M, l, walkable):
    i, j = (l.pop(0))
    nexts = []
    if i !=0:
        nexts.append((i-1, j))
    if i != len(M)-1:
        nexts.append((i+1, j))
    if j != 0:
        nexts.append((i, j-1))
    if j != len(M[0])-1:
        nexts.append((i, j+1))

    for nex in nexts:
        x, y = nex
        if M[x][y] == '.' and not nex in walkable:
            l.append(nex)
            walkable.append(nex)

inp = ''
while '0 0' != (inp = input()):
    i, j = [int(x) for x in inp.split()]
    M = [input() for k in range(j)]
    l = []
    for n in range(j):
        if '@' in M[n]:
            l.append((n, M[n].find('@')))

    walkable = []
    while l:
        search(M, l, walkable)
    print(len(walkable)+1)

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))

Buggy python submission (verdict: Runtime Error):
def search(M, l, walkable):
    i, j = (l.pop(0))
    nexts = []
    if i !=0:
        nexts.append((i-1, j))
    if i != len(M)-1:
        nexts.append((i+1, j))
    if j != 0:
        nexts.append((i, j-1))
    if j != len(M[0])-1:
        nexts.append((i, j+1))

    for nex in nexts:
        x, y = nex
        if M[x][y] == '.' and not nex in walkable:
            l.append(nex)
            walkable.append(nex)

inp = ''
while '0 0' != (inp = input().rstrip()):
    i, j = [int(x) for x in inp.split()]
    M = [input() for k in range(j)]
    l = []
    for n in range(j):
        if '@' in M[n]:
            l.append((n, M[n].find('@')))

    walkable = []
    while l:
        search(M, l, walkable)
    print(len(walkable)+1)

Fixed submission:
import queue

def solve(w, h):
    q = queue.Queue()
    m = [['#' for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        inp = input()
        for j in range(w):
            m[i+1][j+1] = inp[j]
            if m[i+1][j+1] == '@':
                start = [i+1,j+1]
    q.put(start)
    c = 1
    while not q.empty():
        cur = q.get()
        XY = [(1,0), (-1, 0), (0, 1), (0, -1)]
        for x, y in XY:
            cx = cur[0]+x
            cy = cur[1]+y
            if m[cx][cy] == '.':
                m[cx][cy] = '#'
                q.put([cx, cy])
                c+=1
    return c

while True:
    w, h = [int(i) for i in input().split()]
    if w == 0 and h == 0:
        break
    print(solve(w,h))