Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day.

The cloud provider offers m tariff plans, the i-th tariff plan is characterized by the following parameters:

  * l_i and r_i — the i-th tariff plan is available only on days from l_i to r_i, inclusive, 
  * c_i — the number of cores per day available for rent on the i-th tariff plan, 
  * p_i — the price of renting one core per day on the i-th tariff plan. 



Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to c_i) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.

Find the minimum amount of money that Buber will pay for its work for n days from 1 to n. If on a day the total number of cores for all available tariff plans is strictly less than k, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly k cores this day.

Input

The first line of the input contains three integers n, k and m (1 ≤ n,k ≤ 10^6, 1 ≤ m ≤ 2⋅10^5) — the number of days to analyze, the desired daily number of cores, the number of tariff plans.

The following m lines contain descriptions of tariff plans, one description per line. Each line contains four integers l_i, r_i, c_i, p_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ c_i, p_i ≤ 10^6), where l_i and r_i are starting and finishing days of the i-th tariff plan, c_i — number of cores, p_i — price of a single core for daily rent on the i-th tariff plan.

Output

Print a single integer number — the minimal amount of money that Buber will pay.

Examples

Input

5 7 3
1 4 5 3
1 3 5 2
2 5 10 1


Output

44


Input

7 13 5
2 3 10 7
3 5 10 10
1 2 10 6
4 5 10 9
3 4 10 8


Output

462


Input

4 100 3
3 3 2 5
1 1 3 2
2 4 4 4


Output

64
#include <bits/stdc++.h>
using namespace std;
inline int lowbit(int x) { return (x & (-x)); }
int n, k, m;
const int maxn = 1000007;
const int maxp = (1 << 20) + 7;
long long int w[maxp], t[maxp];
vector<int> begins[maxn];
vector<int> vec_ends[maxn];
long long int ans;
struct tariff {
  int l, r, c, p;
} data[maxn];
void update(int c, int p) {
  long long int tmp = 1LL * c * p;
  for (int j = p; j < maxp; j += lowbit(j)) {
    t[j] += c;
    w[j] += tmp;
  }
}
long long int GetAns(int mm) {
  int cur = 0, k = mm;
  long long int res = 0;
  for (int i = 19; i >= 0; i--) {
    if (k > t[cur | (1 << i)]) {
      k -= t[cur | (1 << i)];
      res += w[cur | (1 << i)];
      cur |= (1 << i);
    }
  }
  if (t[1 << 20] >= mm) {
    res += 1LL * k * (cur + 1);
  }
  return res;
}
int main() {
  cin >> n >> k >> m;
  for (int i = 0; i < m; i++)
    cin >> data[i].l >> data[i].r >> data[i].c >> data[i].p;
  for (int i = 0; i < m; i++) {
    begins[data[i].l].push_back(i);
    vec_ends[data[i].r + 1].push_back(i);
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    for (auto& j : begins[i]) {
      update(data[j].c, data[j].p);
    }
    for (auto& j : vec_ends[i]) {
      update(-data[j].c, data[j].p);
    }
    ans += GetAns(k);
  }
  cout << ans << endl;
}
