def automataIteration(grid, minCount, makePillars):
    new_grid = [row[:] for row in grid]
    for i in range(1, (len(grid) - 1)):
        for j in range(1, (len(grid[0]) - 1)):
            count = 0
            for k in range((- 1), 2):
                for l in range((- 1), 2):
                    if (grid[(i + k)][(j + l)] == 1):
                        count += 1
            if ((count >= minCount) or ((count == 0) and (makePillars == 1))):
                new_grid[i][j] = 1
            else:
                new_grid[i][j] = 0
    return new_grid
def automataIteration(grid, minCount, makePillars):
    new_grid = [row[:] for row in grid]
    for i in range(1, (len(grid) - 1)):
        for j in range(1, (len(grid[0]) - 1)):
            count = 0
            for k in range((- 1), 2):
                for l in range((- 1), 2):
                    if (grid[(i + k)][(j + l)] == 1):
                        count += 1
            if ((count >= minCount) or ((count == 0) and (makePillars == 1))):
                new_grid[i][j] = 1
            else:
                new_grid[i][j] = 0
    return new_grid