Periodic Function (Hard)
Time limit1sMemory limit1024 MB
Given the integrals of a periodic function over each unit interval [i-1, i], print the integral over [a, b] using the function's period.
- Level
Medium6 of 10
- Topics
- Prefix sum, String matching, Math
- Solved
- No attempts yet
Problem
This problem has different input constraints from Periodic Function (Easy).
A periodic function is a function whose values repeat at regular intervals. If there exists a positive number such that for all , then is called a periodic function, and is called a period. A function can have several periods. For example, if , then can be a period for every positive integer .
Periodic functions make definite integrals easier to compute, because shifting the integration interval by a period does not change the value. For example, the period of is , so .
Every day, Dooyoung brings Ian a periodic function that Ian does not know, gives him the integral over an arbitrary interval, and asks him to find the integral over another given interval. Tired of solving these by hand, Ian wants a program that computes the answers automatically.
Input
The first line contains the length of the interval array.
The second line contains integers separated by spaces. For each integer with , the -th number is .
The third line contains two integers and separated by a space, the endpoints of the interval to find.
Output
Print the value of on one line.
Constraints
- The absolute value of every integral value is at most .
- All input values are integers.
- The length of the period is guaranteed to be an integer at most .