#include <bits/stdc++.h>
using namespace std;
long long m, n, x, y, z, k;
pair<pair<long long, long long>, pair<long long, long long> > ara[300000];
vector<long long> vec, tmp, tmp1;
long long actanss[1000009];
long long lagbe[1000009];
void fnc(long long beg, long long ed, vector<long long> &vec) {
  if (beg == ed) {
    for (long long val : vec) {
      long long l = ara[beg].second.first;
      long long r = ara[beg].second.second;
      long long koytaDibe = ara[beg].first.second;
      long long price = ara[beg].first.first;
      if (val < l || val > r) continue;
      actanss[val] += min(lagbe[val], koytaDibe) * price;
    }
    return;
  }
  long long mid = (beg + ed) / 2;
  vector<long long> vec1, vec2;
  tmp.clear();
  tmp1.clear();
  tmp.resize(vec.size() + 2);
  tmp1.resize(vec.size() + 2);
  for (long long i = beg; i <= mid; i++) {
    long long l = ara[i].second.first;
    long long r = ara[i].second.second;
    long long koytaDibe = ara[i].first.second;
    long long price = ara[i].first.first;
    long long pos1 = lower_bound(vec.begin(), vec.end(), l) - vec.begin();
    long long pos2 = upper_bound(vec.begin(), vec.end(), r) - vec.begin();
    tmp[pos1] += koytaDibe;
    tmp[pos2] -= koytaDibe;
    tmp1[pos1] += (koytaDibe * price);
    tmp1[pos2] -= (koytaDibe * price);
  }
  for (long long i = 1; i < tmp.size(); i++) {
    tmp[i] += tmp[i - 1];
    tmp1[i] += tmp1[i - 1];
  }
  for (long long i = 0; i < vec.size(); i++) {
    long long needed = lagbe[vec[i]];
    if (needed <= tmp[i]) {
      vec1.push_back(vec[i]);
    } else {
      lagbe[vec[i]] -= tmp[i];
      actanss[vec[i]] += tmp1[i];
      vec2.push_back(vec[i]);
    }
  }
  fnc(beg, mid, vec1);
  fnc(mid + 1, ed, vec2);
}
int main() {
  cin >> n >> k >> m;
  for (long long i = 1; i <= n; i++) lagbe[i] = k;
  for (long long i = 1; i <= m; i++) {
    long long l, r, c, p;
    scanf("%lld %lld %lld %lld", &l, &r, &c, &p);
    ara[i] = {{p, c}, {l, r}};
  }
  sort(ara + 1, ara + m + 1);
  for (long long i = 1; i <= m; i++) {
    long long l = ara[i].second.first;
    long long r = ara[i].second.second;
    long long koytaDibe = ara[i].first.second;
    long long price = ara[i].first.first;
  }
  for (long long i = 1; i <= n; i++) vec.push_back(i);
  fnc(1, m, vec);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += actanss[i];
  }
  cout << ans << endl;
  return 0;
}
