#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;
}
