Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

p_grid = {(0, 0): 0, (H - 1, W - 1): -1}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    grid[here[0]][here[1]] = False
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        p_grid[a] = p_grid[here] + 1
    queue.extend(arounds)

if p_grid[H-1, W-1] == -1:
    print('-1')
else:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]
    return list(filter(lambda a: a[0] >= 0 and a[0] < max_x and
                                 a[1] >= 0 and a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

p_grid = {(0, 0): 0, (H - 1, W - 1): -1}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    grid[here[0]][here[1]] = False
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        p_grid[a] = p_grid[here] + 1
    queue.extend(arounds)

if p_grid[H-1, W-1] == -1:
    print('-1')
else:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]
    return list(filter(lambda a: a[0] >= 0 and a[0] < max_x and
                                 a[1] >= 0 and a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = []
for i in range(0, H):
    for j in range(0, W):
        if not grid[i][j]:
            black.append((i, j))

s_path = []
queue = deque([[(0, 0)]])
while not len(queue) == 0:
    path = queue.popleft()
    here = path[-1]
    if here == (H - 1, W - 1):
        s_path = path
        break;
    grid[here[0]][here[1]] = False
    arounds = get_arounds(here, grid, H, W)
    if len(arounds) == 0:
        continue;
    queue.extend(list(map(lambda a: path + [a], arounds)))
else:
    s_path = []

if len(s_path) == 0:
    print('-1')
else:
    print(H * W - len(s_path) - len(black))


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]
    return list(filter(lambda a: a[0] >= 0 and a[0] < max_x and
                                 a[1] >= 0 and a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = []
for i in range(0, H):
    for j in range(0, W):
        if not grid[i][j]:
            black.append((i, j))

s_path = []
queue = deque([[(0, 0)]])
while not len(queue) == 0:
    path = queue.popleft()
    here = path[-1]
    if here == (H - 1, W - 1):
        s_path = path
        break;
    grid[here[0]][here[1]] = False
    arounds = get_arounds(here, grid, H, W)
    queue.extend(list(map(lambda a: path + [a], arounds)))
else:
    s_path = []

if len(s_path) == 0:
    print('-1')
else:
    print(H * W - len(s_path) - len(black))


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = tuple(map(int, input().split(' ')))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

def get_arounds(x, y, max_x, max_y):
    arounds = [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]
    return list(filter(lambda a: a[0] >= 0 and a[0] < max_x and
                                 a[1] >= 0 and a[1] < max_y, arounds))

def find_path(point, path, ignore, H, W):
    x = point[0]
    y = point[1]
    arounds = get_arounds(x, y, H, W)
    targets = list(filter(lambda x: not x in ignore, arounds))

    if len(targets) == 0:
        return [(False, path, ignore)]
    else:
        return [(True, path + [target], ignore + arounds)
                for target in targets]


ignore = []
for i in range(0, H):
    for j in range(0, W):
        if not grid[i][j]:
            ignore.append((i, j))

paths = [(True, [(0, 0)], ignore)]
s_path = []
while any([p[0] for p in paths]):
    next_paths = []
    for p in filter(lambda p: p[0], paths):
        if p[1][-1] == (H - 1, W - 1):
            s_path = p[1]
            break

        next_paths.extend(find_path(p[1][-1], p[1], p[2], H, W))
    paths = next_paths

if len(s_path) == 0:
    print(-1)
else:
    print(H * W - len(s_path) - len(ignore))


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
H, W = tuple(map(int, input().split(' ')))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

def get_arounds(x, y, max_x, max_y):
    arounds = [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]
    return list(filter(lambda a: a[0] >= 0 and a[0] < max_x and
                                 a[1] >= 0 and a[1] < max_y, arounds))

def find_path(point, path, ignore, H, W):
    x = point[0]
    y = point[1]
    arounds = get_arounds(x, y, H, W)
    targets = list(filter(lambda x: not x in ignore, arounds))

    if len(targets) == 0:
        return [(False, path, ignore)]
    else:
        return [(True, path + [target], ignore + arounds)
                for target in targets]


ignore = []
for i in range(0, H):
    for j in range(0, W):
        if not grid[i][j]:
            ignore.append((i, j))

paths = [(True, [(0, 0)], ignore)]
s_path = []
while any([p[0] for p in paths]):
    print('.', endl='')
    next_paths = []
    for p in filter(lambda p: p[0], paths):
        if p[1][-1] == (H - 1, W - 1):
            s_path = p[1]
            break

        next_paths.extend(find_path(p[1][-1], p[1], p[2], H, W))
    paths = next_paths

if len(s_path) == 0:
    print(-1)
else:
    print(H * W - len(s_path) - len(ignore))


Fixed submission:
from collections import deque


def get_arounds(point, grid, max_x, max_y):
    x = point[0]
    y = point[1]
    arounds = [(x + dx, y + dy) for dx, dy in ((0, -1), (1, 0), (0, 1), (-1, 0))]
    return list(filter(lambda a: 0 <= a[0] < max_x and
                                 0 <= a[1] < max_y and
                                 grid[a[0]][a[1]], arounds))


H, W = tuple(map(int, input().split()))

grid = []
for i in range(0, H):
    grid.append(list(map(lambda x: True if x == '.' else False, list(input()))))

black = sum(map(lambda l: l.count(False), grid))

grid[0][0] = False
p_grid = {(0, 0): 0}
queue = deque([(0, 0)])
while not len(queue) == 0:
    here = queue.popleft()
    if here == (H - 1, W - 1):
        break;
    arounds = get_arounds(here, grid, H, W)
    for a in arounds:
        grid[a[0]][a[1]] = False
        p_grid[a] = p_grid[here] + 1
    if not arounds:
        continue
    queue.extend(arounds)

if (H-1, W-1) in p_grid:
    print(H * W - (p_grid[H-1, W-1] + 1) - black)
else:
    print(-1)