#include <bits/stdc++.h>
using namespace std;
template <typename T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <typename T>
void read(vector<T>& arr, long long N) {
  arr.clear();
  arr.resize(N);
  for (long long i = 0; i < N; i++) cin >> arr[i];
}
template <typename T>
void read(vector<pair<T, T>>& arr, long long N) {
  arr.clear();
  arr.resize(N);
  for (long long i = 0; i < (long long)arr.size(); i++)
    cin >> arr[i].first >> arr[i].second;
}
template <typename T>
void read(vector<vector<T>>& arr, long long N, long long M) {
  arr.clear();
  arr.resize(N, vector<T>(M));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) cin >> arr[i][j];
  }
}
template <typename T>
void print(vector<T>& arr) {
  for (auto it : arr) cout << it << ' ';
  cout << '\n';
}
template <typename T>
void print(vector<pair<T, T>>& arr) {
  for (auto it : arr) cout << " { " << it.first << ',' << it.second << " } ";
  cout << '\n';
}
template <typename T>
void print(vector<vector<T>>& arr) {
  for (auto it : arr) {
    for (auto ut : it) cout << ut << ' ';
    cout << '\n';
  }
  cout << '\n';
}
template <typename T>
void print(list<T>& arr) {
  for (auto it = (arr).begin(); it != (arr).end(); it++) cout << *it << ' ';
  cout << '\n';
}
template <typename T>
void print(unordered_set<T>& ss) {
  for (auto it = (ss).begin(); it != (ss).end(); it++) cout << *it << ' ';
  cout << '\n';
}
template <typename T>
void print(set<T>& ss) {
  for (auto it = (ss).begin(); it != (ss).end(); it++) cout << *it << ' ';
  cout << '\n';
}
bool lexi(string& s1, string& s2) {
  long long I = s1.size(), J = s2.size(), i = 0, j = 0;
  while (i < I and j < J) {
    if (s1[i] > s2[j]) return true;
    if (s1[i] < s2[j]) return false;
    i++;
    j++;
  }
  if (I >= J) return true;
  return false;
}
struct uf {
  vector<long long> par, size;
  void init(long long N) {
    par.resize(N, -1);
    size.resize(N, 1);
  }
  long long root(long long a) {
    if (par[a] == -1) return a;
    return par[a] = root(par[a]);
  }
  void unite(long long a, long long b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) {
      par[a] = b;
      size[b] += size[a];
    } else {
      par[b] = a;
      size[a] += size[b];
    }
  }
  bool same(long long a, long long b) {
    if (root(a) == root(b)) return true;
    return false;
  }
};
struct seg_tree {
  vector<long long> make;
  long long siz;
  vector<long long> arr;
  void init(vector<long long>& a, bool max, bool range) {
    arr.clear();
    make.clear();
    arr = a;
    siz = arr.size();
    make.resize(4 * siz);
    if (max)
      build_max(0, 0, siz - 1);
    else if (range)
      build_range(0, 0, siz - 1);
  }
  long long get_max(long long L, long long R) {
    return Get_max(0, 0, siz - 1, L, R);
  }
  void update_max(long long index, long long val) {
    Update_max(0, 0, siz - 1, index, val);
    return;
  }
  long long get_sum(long long L, long long R) {
    return Get_sum(0, 0, siz - 1, L, R);
  }
  void update_range(long long index, long long add) {
    Update_range(0, 0, siz - 1, index, add);
    return;
  }
  long long build_range(long long ind, long long L, long long R) {
    if (L == R) {
      make[ind] = arr[L];
      return make[ind];
    } else {
      long long mid = (L + R) / 2;
      long long a = build_range(2 * ind + 1, L, mid);
      long long b = build_range(2 * ind + 2, mid + 1, R);
      make[ind] = a + b;
      return make[ind];
    }
  }
  long long Get_sum(long long ind, long long L, long long R, long long Left,
                    long long Right) {
    if (L > Right or R < Left) return 0;
    if (Left <= L and R <= Right) return make[ind];
    long long mid = (L + R) / 2;
    long long a = Get_sum(2 * ind + 1, L, mid, Left, Right);
    long long b = Get_sum(2 * ind + 2, mid + 1, R, Left, Right);
    return a + b;
  }
  void Update_range(long long ind, long long L, long long R, long long index,
                    long long add) {
    if (L == R) {
      make[ind] += add;
      arr[index] += add;
    } else {
      long long mid = (L + R) / 2;
      if (L <= index and index <= R) {
        Update_range(2 * ind + 1, L, mid, index, add);
      } else {
        Update_range(2 * ind + 2, mid + 1, R, index, add);
      }
      make[ind] = make[2 * ind + 1] + make[2 * ind + 2];
    }
  }
  long long build_max(long long ind, long long L, long long R) {
    if (L == R) {
      make[ind] = arr[L];
      return make[ind];
    } else {
      long long mid = (L + R) / 2;
      return make[ind] = max(build_max(2 * ind + 1, L, mid),
                             build_max(2 * ind + 2, mid + 1, R));
    }
  }
  long long Get_max(long long ind, long long L, long long R, long long Left,
                    long long Right) {
    if (R < Left or L > Right) return -1e15;
    if (Left <= L and R <= Right) return make[ind];
    long long mid = (L + R) / 2;
    return max(Get_max(2 * ind + 1, L, mid, Left, Right),
               Get_max(2 * ind + 2, mid + 1, R, Left, Right));
  }
  long long Update_max(long long ind, long long L, long long R, long long index,
                       long long val) {
    if (L == R) {
      arr[index] = val;
      make[ind] = val;
      return val;
    } else {
      long long mid = (L + R) / 2;
      if (L <= index and index <= mid) {
        make[ind] = Update_max(2 * ind + 1, L, mid, index, val);
      } else {
        make[ind] = Update_max(2 * ind + 2, mid + 1, R, index, val);
      }
      make[ind] = max(make[2 * ind + 1], make[2 * ind + 2]);
      return make[ind];
    }
  }
};
static bool comp(pair<long long, long long>& a, pair<long long, long long>& b) {
  if (a.first < b.first) return true;
  if (a.first == b.first) {
    if (a.second < b.second) return true;
  }
  return false;
}
long long Max = 1e17, Min = -1e16;
long long N, M, K, D;
long long mod = 1e9 + 7;
void solve() {
  cin >> N;
  vector<pair<long long, long long>> arr(N);
  for (long long i = 0; i < N; i++) cin >> arr[i].second >> arr[i].first;
  sort(arr.begin(), arr.end());
  long long t;
  cin >> t;
  vector<long long> p(t);
  for (long long i = 0; i < t; i++) {
    cin >> p[i];
  }
  p.push_back(Max);
  long long ans = 0;
  long long l = 0, now = 0;
  for (long long i = 0; i < N; i++) {
    while (arr[i].second > 0) {
      long long mini = min(p[l] - now, arr[i].second);
      arr[i].second -= mini;
      ans += mini * (l + 1) * arr[i].first;
      now += mini;
      if (now >= p[l]) l++;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  auto start_time = chrono::high_resolution_clock::now();
  bool test = 0;
  if (!test)
    solve();
  else {
    long long tt;
    cin >> tt;
    while (tt--) solve();
  }
  auto end_time = chrono::high_resolution_clock::now();
  return 0;
}

### Prompt

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

Vasya plays the Geometry Horse.

The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. 

There are n types of geometric figures. The number of figures of type ki and figure cost ci is known for each figure type. A player gets ci·f points for destroying one figure of type i, where f is the current factor. The factor value can be an integer number from 1 to t + 1, inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 ≤ i ≤ t) figures, so the (pi + 1)-th figure to be destroyed is considered with factor equal to i + 1.

Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.

Input

The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types.

Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly.

The next line contains the only integer number t (1 ≤ t ≤ 100) — the number that describe the factor's changes. 

The next line contains t integer numbers pi (1 ≤ p1 < p2 < ... < pt ≤ 1012), separated with spaces.

Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Output

Print the only number — the maximum number of points Vasya can get.

Examples

Input

1
5 10
2
3 6


Output

70

Input

2
3 8
5 10
1
20


Output

74

Note

In the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points.

In the second example all 8 figures will be destroyed with factor 1, so Vasya will get (3·8 + 5·10)·1 = 74 points.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <typename T>
void read(vector<T>& arr, long long N) {
  arr.clear();
  arr.resize(N);
  for (long long i = 0; i < N; i++) cin >> arr[i];
}
template <typename T>
void read(vector<pair<T, T>>& arr, long long N) {
  arr.clear();
  arr.resize(N);
  for (long long i = 0; i < (long long)arr.size(); i++)
    cin >> arr[i].first >> arr[i].second;
}
template <typename T>
void read(vector<vector<T>>& arr, long long N, long long M) {
  arr.clear();
  arr.resize(N, vector<T>(M));
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < M; j++) cin >> arr[i][j];
  }
}
template <typename T>
void print(vector<T>& arr) {
  for (auto it : arr) cout << it << ' ';
  cout << '\n';
}
template <typename T>
void print(vector<pair<T, T>>& arr) {
  for (auto it : arr) cout << " { " << it.first << ',' << it.second << " } ";
  cout << '\n';
}
template <typename T>
void print(vector<vector<T>>& arr) {
  for (auto it : arr) {
    for (auto ut : it) cout << ut << ' ';
    cout << '\n';
  }
  cout << '\n';
}
template <typename T>
void print(list<T>& arr) {
  for (auto it = (arr).begin(); it != (arr).end(); it++) cout << *it << ' ';
  cout << '\n';
}
template <typename T>
void print(unordered_set<T>& ss) {
  for (auto it = (ss).begin(); it != (ss).end(); it++) cout << *it << ' ';
  cout << '\n';
}
template <typename T>
void print(set<T>& ss) {
  for (auto it = (ss).begin(); it != (ss).end(); it++) cout << *it << ' ';
  cout << '\n';
}
bool lexi(string& s1, string& s2) {
  long long I = s1.size(), J = s2.size(), i = 0, j = 0;
  while (i < I and j < J) {
    if (s1[i] > s2[j]) return true;
    if (s1[i] < s2[j]) return false;
    i++;
    j++;
  }
  if (I >= J) return true;
  return false;
}
struct uf {
  vector<long long> par, size;
  void init(long long N) {
    par.resize(N, -1);
    size.resize(N, 1);
  }
  long long root(long long a) {
    if (par[a] == -1) return a;
    return par[a] = root(par[a]);
  }
  void unite(long long a, long long b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) {
      par[a] = b;
      size[b] += size[a];
    } else {
      par[b] = a;
      size[a] += size[b];
    }
  }
  bool same(long long a, long long b) {
    if (root(a) == root(b)) return true;
    return false;
  }
};
struct seg_tree {
  vector<long long> make;
  long long siz;
  vector<long long> arr;
  void init(vector<long long>& a, bool max, bool range) {
    arr.clear();
    make.clear();
    arr = a;
    siz = arr.size();
    make.resize(4 * siz);
    if (max)
      build_max(0, 0, siz - 1);
    else if (range)
      build_range(0, 0, siz - 1);
  }
  long long get_max(long long L, long long R) {
    return Get_max(0, 0, siz - 1, L, R);
  }
  void update_max(long long index, long long val) {
    Update_max(0, 0, siz - 1, index, val);
    return;
  }
  long long get_sum(long long L, long long R) {
    return Get_sum(0, 0, siz - 1, L, R);
  }
  void update_range(long long index, long long add) {
    Update_range(0, 0, siz - 1, index, add);
    return;
  }
  long long build_range(long long ind, long long L, long long R) {
    if (L == R) {
      make[ind] = arr[L];
      return make[ind];
    } else {
      long long mid = (L + R) / 2;
      long long a = build_range(2 * ind + 1, L, mid);
      long long b = build_range(2 * ind + 2, mid + 1, R);
      make[ind] = a + b;
      return make[ind];
    }
  }
  long long Get_sum(long long ind, long long L, long long R, long long Left,
                    long long Right) {
    if (L > Right or R < Left) return 0;
    if (Left <= L and R <= Right) return make[ind];
    long long mid = (L + R) / 2;
    long long a = Get_sum(2 * ind + 1, L, mid, Left, Right);
    long long b = Get_sum(2 * ind + 2, mid + 1, R, Left, Right);
    return a + b;
  }
  void Update_range(long long ind, long long L, long long R, long long index,
                    long long add) {
    if (L == R) {
      make[ind] += add;
      arr[index] += add;
    } else {
      long long mid = (L + R) / 2;
      if (L <= index and index <= R) {
        Update_range(2 * ind + 1, L, mid, index, add);
      } else {
        Update_range(2 * ind + 2, mid + 1, R, index, add);
      }
      make[ind] = make[2 * ind + 1] + make[2 * ind + 2];
    }
  }
  long long build_max(long long ind, long long L, long long R) {
    if (L == R) {
      make[ind] = arr[L];
      return make[ind];
    } else {
      long long mid = (L + R) / 2;
      return make[ind] = max(build_max(2 * ind + 1, L, mid),
                             build_max(2 * ind + 2, mid + 1, R));
    }
  }
  long long Get_max(long long ind, long long L, long long R, long long Left,
                    long long Right) {
    if (R < Left or L > Right) return -1e15;
    if (Left <= L and R <= Right) return make[ind];
    long long mid = (L + R) / 2;
    return max(Get_max(2 * ind + 1, L, mid, Left, Right),
               Get_max(2 * ind + 2, mid + 1, R, Left, Right));
  }
  long long Update_max(long long ind, long long L, long long R, long long index,
                       long long val) {
    if (L == R) {
      arr[index] = val;
      make[ind] = val;
      return val;
    } else {
      long long mid = (L + R) / 2;
      if (L <= index and index <= mid) {
        make[ind] = Update_max(2 * ind + 1, L, mid, index, val);
      } else {
        make[ind] = Update_max(2 * ind + 2, mid + 1, R, index, val);
      }
      make[ind] = max(make[2 * ind + 1], make[2 * ind + 2]);
      return make[ind];
    }
  }
};
static bool comp(pair<long long, long long>& a, pair<long long, long long>& b) {
  if (a.first < b.first) return true;
  if (a.first == b.first) {
    if (a.second < b.second) return true;
  }
  return false;
}
long long Max = 1e17, Min = -1e16;
long long N, M, K, D;
long long mod = 1e9 + 7;
void solve() {
  cin >> N;
  vector<pair<long long, long long>> arr(N);
  for (long long i = 0; i < N; i++) cin >> arr[i].second >> arr[i].first;
  sort(arr.begin(), arr.end());
  long long t;
  cin >> t;
  vector<long long> p(t);
  for (long long i = 0; i < t; i++) {
    cin >> p[i];
  }
  p.push_back(Max);
  long long ans = 0;
  long long l = 0, now = 0;
  for (long long i = 0; i < N; i++) {
    while (arr[i].second > 0) {
      long long mini = min(p[l] - now, arr[i].second);
      arr[i].second -= mini;
      ans += mini * (l + 1) * arr[i].first;
      now += mini;
      if (now >= p[l]) l++;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  auto start_time = chrono::high_resolution_clock::now();
  bool test = 0;
  if (!test)
    solve();
  else {
    long long tt;
    cin >> tt;
    while (tt--) solve();
  }
  auto end_time = chrono::high_resolution_clock::now();
  return 0;
}

```