Truck Parking Fees

Interview

Time limit1sMemory limit128 MB

Summary
Given per-truck rates depending on how many of three trucks overlap in time, compute the total parking fee over discrete minute intervals.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

A driver owns three trucks. The parking lot charges a discounted per-truck fee depending on how many of the trucks are parked at the same time.

If exactly one truck is parked, the fee is A won per minute for that truck. If exactly two trucks are parked, the fee is B won per minute for each truck. If all three trucks are parked, the fee is C won per minute for each truck.

Given A, B, C and the arrival and departure times of the three trucks, compute the total parking fee. A truck is considered parked from its arrival time up to, but not including, its departure time.

Input

The first line contains the parking fees A, B, and C separated by spaces. (1 <= C <= B <= A <= 100)

Each of the next three lines contains two integers: the arrival time and departure time of one truck. The arrival time is always earlier than the departure time, and every time is an integer from 1 to 100 inclusive.

Output

Print the total parking fee for the three trucks.

Examples2

  1. Example 1

    Input
    5 3 1
    1 6
    3 5
    2 8
    
    Expected output
    33
    
  2. Example 2

    Input
    10 8 6
    15 30
    25 50
    70 80
    
    Expected output
    480