##### Woburn Challenge 2017-18 Round 1 - Senior Division

A certain TTC bus route involves a sequence of bus stops, numbered from to .

Every minutes, starting at time , a new bus will arrive at stop . It will wait a brief moment to allow new passengers to board and/or existing passengers to disembark, and then proceed onwards to stop , reaching it after another minutes. There, it will similarly give passengers an opportunity to board/disembark, before continuing onwards and reaching stop after another minutes, and so on. In this manner, minutes after any given bus starts its route, it will arrive at stop , drop off any remaining passengers, and then go out of service. Note that a new bus drives along the route described above every minutes, meaning that there may be multiple buses on the road at any time.

Each bus has a maximum capacity of passengers. If some passengers want to get off a bus while others simultaneously want to get on it, the former can happen first to make room for the new passengers. Note that buses take no extra time to pick up or drop off any number of passengers at a stop.

At time , your entire class of students is waiting at stop , the of whom wants to get to stop as quickly as possible. At any moment, each student not currently on a bus may either wait at their current stop, walk to the next stop along the route in minutes, or board a bus (if there's a below-capacity bus at their current stop at that moment). Meanwhile, each student currently on a bus may get off the bus if it's currently at a stop.

Each student's "travel time" is the amount of time which goes by (after time ) before they arrive at their destination stop. You're thinking it would be nice if the sum of all students' travel times could be as small as possible. As such, you'd like to determine the minimum possible value this sum could have, assuming that all of the students work together to minimize it. Though, on second thought, getting everyone in your class to cooperate might be the more difficult part...

Please note that the answer may not fit into a -bit signed integer.

#### Subtasks

In test cases worth of the points, and .

In test cases worth another of the points, and .

#### Input Specification

The first line of input consists of four space-separated integers, ,
, , and .

The next line consists of two space-separated integers, and .

lines follow, the of which consists of a single integer,
, for .

#### Output Specification

Output a single integer, the minimum possible sum of travel times for all students to reach their desired stops.

#### Sample Input 1

```
2 2 2 1
3 5
2
2
2
```

#### Sample Output 1

`11`

#### Sample Input 2

```
10 3 1 2
4 2
4
3
5
4
```

#### Sample Output 2

`17`

#### Sample Explanation 2

In the first case, one optimal strategy is as follows:

Student : Board the first bus immediately, and disembark at stop (
minutes)

Student : Wait for minutes, board the second bus at time , and
disembark at stop ( minutes)

Student : Walk to stop ( minutes)

In the second case, one optimal strategy is as follows:

Student : Board the first bus immediately, and disembark at stop (
minutes)

Student : Walk all the way to stop ( minutes)

Student : Board the first bus immediately, and disembark at stop (
minutes)

Student : Walk to stop , wait for minutes, board the second bus at
time , and disembark at stop ( minutes)

## Comments