Under construction

Still being built. Things may change

Periodic Function (Easy)

Interview

Time limit0.5sMemory limit1024 MB

Summary
Given the integral of a periodic function over each unit interval in one period, compute the integral over an arbitrary interval [a, b].
Level

Easy3 of 10

Topics
Prefix sum, Math
Solved
No attempts yet

Statement

This problem has different input constraints from Periodic Function (Hard).

A periodic function is a function whose values repeat at regular intervals. Formally, if there is a positive number pp such that f(x+p)=f(x)f(x+p)=f(x) for all xx, then f(x)f(x) is called a periodic function, and pp is called a period. A single function can have several periods. For example, if f(x)=sin⁡xf(x) = \sin x, then 2nπ2n\pi is a period for every positive integer nn.

Periodic functions make definite integrals easier to compute, because shifting the interval by one period does not change the value. For example, the period of sin⁡\sin is 2π2\pi, so ∫0πsin⁡x dx=∫2π3πsin⁡x dx\int_0^\pi \sin x\,dx = \int_{2\pi}^{3\pi} \sin x\,dx.

Every day, Dooyoung brings Ian a periodic function that Ian has never seen. Dooyoung gives the integral over an interval whose length equals the period, and asks Ian to find the integral over another interval. Tired of solving these by hand, Ian wants a program that computes the answers automatically.

Input

The first line contains the period pp of the function.

The second line contains pp integers separated by spaces. For 1≤i≤p1 \le i \le p, the ii-th number is ∫i−1if(x) dx\int_{i-1}^i f(x)\,dx.

The third line contains two integers aa and bb separated by a space, the endpoints of the interval to find.

Output

Print the value of ∫abf(x) dx\int_a^b f(x)\,dx on one line.

Constraints

  • 1≤p≤1051 \le p \le 10^5
  • −109≤a≤b≤109-10^9 \le a \le b \le 10^9
  • The absolute value of every integral is at most 10910^9.
  • All input values are integers.

Examples3

  1. Example 1

    Input
    10
    1 2 3 1 2 3 1 2 3 1
    2 5
    
    Expected output
    6
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    9 9
    
    Expected output
    0
    
  3. Example 3

    Input
    4
    1 2 4 8
    -5 -3
    
    Expected output
    9