#include <bits/stdc++.h>
using namespace std;
struct Period {
  int l;
  int r;
};
int main() {
  int n, P1, P2, P3, T1, T2;
  Period* p = NULL;
  int result = 0;
  cin >> n;
  cin >> P1 >> P2 >> P3 >> T1 >> T2;
  p = new Period[n];
  for (int i = 0; i < n; ++i) {
    cin >> p[i].l;
    cin >> p[i].r;
  }
  if (n == 1) {
    result = (p[0].r - p[0].l) * P1;
    cout << result;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    int timeBreak = 0;
    result += (p[i].r - p[i].l) * P1;
    if (i + 1 < n) {
      timeBreak = p[i + 1].l - p[i].r;
      if (timeBreak <= T1) {
        result += timeBreak * P1;
      } else {
        timeBreak -= T1;
        result += T1 * P1;
        if (timeBreak <= T2) {
          result += timeBreak * P2;
        } else {
          result += T2 * P2;
          timeBreak -= T2;
          result += timeBreak * P3;
        }
      }
    }
  }
  cout << result << endl;
  delete[] p;
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1, r1], [l2, r2], ..., [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

Input

The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

Output

Output the answer to the problem.

Examples

Input

1 3 2 1 5 10
0 10


Output

30

Input

2 8 4 2 5 10
20 30
50 100


Output

570

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Period {
  int l;
  int r;
};
int main() {
  int n, P1, P2, P3, T1, T2;
  Period* p = NULL;
  int result = 0;
  cin >> n;
  cin >> P1 >> P2 >> P3 >> T1 >> T2;
  p = new Period[n];
  for (int i = 0; i < n; ++i) {
    cin >> p[i].l;
    cin >> p[i].r;
  }
  if (n == 1) {
    result = (p[0].r - p[0].l) * P1;
    cout << result;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    int timeBreak = 0;
    result += (p[i].r - p[i].l) * P1;
    if (i + 1 < n) {
      timeBreak = p[i + 1].l - p[i].r;
      if (timeBreak <= T1) {
        result += timeBreak * P1;
      } else {
        timeBreak -= T1;
        result += T1 * P1;
        if (timeBreak <= T2) {
          result += timeBreak * P2;
        } else {
          result += T2 * P2;
          timeBreak -= T2;
          result += timeBreak * P3;
        }
      }
    }
  }
  cout << result << endl;
  delete[] p;
  return 0;
}

```