Under construction

Still being built. Things may change

Traffic Jam

Interview

Time limit2sMemory limit1024 MB

Summary
Given cars with start delays a_i and a repeating green-red light, find the time the last car passes the light.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Statement

A one-way road has a traffic light. There are nn cars waiting on the road, and each driver wants to pass as quickly as possible. Drivers never run a red light, so they must wait for green.

The light has only red and green. Green stays on for gg seconds, then red for rr seconds, then green again for gg seconds, and so on. At the first moment the light is green. A car may pass at the moment the light switches.

It is 7 a.m., and the drivers are sleepy. The ii-th driver needs aia_i seconds to realize that the light is green. The first car in line can start aia_i seconds after green begins. Each other car can start aia_i seconds after the car in front of it starts moving. Cars move fast, so the time to reach the light and pass through it is ignored. No car passes on red.

Find the time, counted from the first green, at which the last car passes the light.

Input

The first line contains integers nn (1≤n≤10001 \le n \le 1000), gg, and rr (1≤g,r≤1091 \le g, r \le 10^9): the number of cars, the green duration, and the red duration, in seconds. The second line contains nn integers aia_i (0≤ai≤g0 \le a_i \le g): the seconds each driver needs to realize the light is green.

Output

Print one integer: the time at which the last car passes the light.

Examples1

  1. Example 1

    Input
    4 10 5
    10 4 4 7
    
    Expected output
    37