def find_optimal_vertical_seam(cumulativeEnergyMap):
    rows, columns = cumulativeEnergyMap.shape
    minEnergy = cumulativeEnergyMap[rows-1][0]
    mincol = 0
    for c in range(columns):
            if minEnergy > min(minEnergy, getElement(rows-1, c, cumulativeEnergyMap)):
                mincol = c
                minEnergy = cumulativeEnergyMap[rows-1][c]

    colVector = []
    colVector.append(mincol)
    
    for r in reversed(range(rows-1)):
            minval = min(getElement(r, mincol, cumulativeEnergyMap), getElement(r, mincol-1, cumulativeEnergyMap), getElement(r, mincol+1, cumulativeEnergyMap))
            if minval == getElement(r, mincol, cumulativeEnergyMap):
                colVector.append(mincol)
            elif minval == getElement(r, mincol-1, cumulativeEnergyMap):
                colVector.append(mincol-1)
                mincol = mincol-1
            else:
                colVector.append(mincol+1)
                mincol = mincol=1
    return colVector[::-1]
def find_optimal_horizontal_seam(cumulativeEnergyMap):
    rows, columns = cumulativeEnergyMap.shape
    minEnergy = cumulativeEnergyMap[0][columns-1]
    minrow = 0
    for r in range(rows):
            if (minEnergy > min(minEnergy, getElement(r, columns-1, cumulativeEnergyMap))):
                minrow = r
                minEnergy = cumulativeEnergyMap[r][columns-1]
    colVector = []
    colVector.append(minrow)
    
    for c in reversed(range(columns-1)):
            minval = min(getElement( minrow,c, cumulativeEnergyMap), getElement(minrow-1,c, cumulativeEnergyMap), getElement(minrow+1, c, cumulativeEnergyMap))
            if minval == getElement( minrow, c, cumulativeEnergyMap):
                colVector.append(minrow)
            elif minval == getElement(minrow-1,c, cumulativeEnergyMap):
                colVector.append(minrow-1)
                minrow = minrow-1
            else:
                colVector.append(minrow+1)
                minrow = minrow+1

    return colVector[::-1]