Company: Typeface_10sep
Difficulty: medium
Pipeline Response Time Sum Problem Description A system is made of n software components standing in a row. The array responseTime gives the time each component takes to complete its task: responseTime[i] is the response time of the i -th component. Any contiguous group of one or more components (a contiguous subarray of responseTime ) is called a pipeline . The response time of a pipeline is defined as: Pipeline Response Time = (maximum response time in the pipeline) * (number of components in the pipeline) Return the sum of the response times of all possible pipelines , modulo 10^9 + 7 . There are n * (n + 1) / 2 pipelines in total, one for every choice of a start index and an end index with start <= end. Input Format Read from standard input. n responseTime[0] responseTime[1] ... responseTime[n-1] Line 1 contains the integer n , the number of components. Each of the next n lines contains one integer, responseTime[i] . Output Format Print a single integer: the sum of the response