

def unique_paths_obstacles(obstacles):
    obstacles[0][0] = 0 if obstacles[0][0] else 1
    for i in xrange(1, len(obstacles[0])):
        obstacles[0][i] = 0 if obstacles[0][i] else obstacles[0][i - 1]

    for i in xrange(1, len(obstacles)):
        obstacles[i][0] = 0 if obstacles[i][0] else obstacles[i - 1][0]

    for i in xrange(1, len(obstacles)):
        for j in xrange(1, len(obstacles[0])):
            obstacles[i][j] = 0 if obstacles[i][j] else obstacles[i - 1][j] + obstacles[i][j - 1]

    return obstacles[-1][-1]


if __name__ == '__main__':
    print unique_paths_obstacles([
        [0,0,0],
        [0,1,0],
        [0,0,0]
    ])