def getPoolSize(array):
    topVertex = None
    poolSize = 0

    for i in xrange(1, len(array)-1):
        if not topVertex:
            topVertex = i
            continue

        # The end of pool
        if array[i] >= array[topVertex]:
            topVertex = i

        poolSize += array[topVertex] - array[i] 

    return poolSize


if __name__ == "__main__":
    poolsArrays = ( [2, 5, 1, 2, 3, 4, 7, 7, 6],
                    [2, 5, 1, 3, 1, 2, 1, 7, 7, 6],
                    [2, 5, 1, 5, 1, 5],
                    [1, 5, 4, 3, 2, 1],
                    [0, 5, 0, 1, 0, 2, 0])
    for pool in poolsArrays:
        print ( getPoolSize(pool) )

    