#C14825. Cumulative Product Calculation with Range

    ID: 44517 Type: Default 1000ms 256MiB

Cumulative Product Calculation with Range

Cumulative Product Calculation with Range

Given a list of integers and an optional subarray range [start, end), compute the cumulative product for the elements in the given range while leaving the other elements unchanged.

The cumulative product for an index i in the range is defined as:

$$result[i] = \prod_{j=start}^{i} a_j$$

For indices outside the specified range, the original value is retained. If the subarray range is not specified, the entire list should be processed.

Note: In the input, if the two integers representing start and end are provided as -1, it indicates that the default range (the entire list) should be used.

inputFormat

The input is taken from stdin and consists of three lines:

  1. An integer n representing the number of elements in the list.
  2. n space-separated integers representing the list.
  3. Two space-separated integers representing start and end. If both are -1, then the entire list is processed.

It is guaranteed that the provided input will be valid.

outputFormat

Output the modified list to stdout as a single line of space-separated integers, where the elements in the specified range have been replaced by their cumulative product, and the others remain unchanged.

## sample
4
1 2 3 4
-1 -1
1 2 6 24