#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 42;
vector<pair<int, pair<int, int> > > g[N];
long long st1[4 * N], st2[4 * N];
long long n, k, m;
void upd(int v, long long tl, long long tr, long long pr, long long am) {
  if (tl == tr) {
    st1[v] += pr * am;
    st2[v] += am;
  } else {
    int tm = (tl + tr) >> 1;
    if (pr <= tm)
      upd((v << 1), tl, tm, pr, am);
    else
      upd((v << 1) + 1, tm + 1, tr, pr, am);
    st1[v] = (st1[(v << 1)] + st1[(v << 1) + 1]);
    st2[v] = (st2[(v << 1)] + st2[(v << 1) + 1]);
  }
}
long long get(int v, int tl, int tr, long long ck) {
  if (st2[v] <= ck) return st1[v];
  if (tl == tr) return tl * ck;
  int tm = (tl + tr) >> 1;
  if (st2[(v << 1)] >= ck)
    return get((v << 1), tl, tm, ck);
  else
    return st1[(v << 1)] + get((v << 1) + 1, tm + 1, tr, ck - st2[(v << 1)]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> m;
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    g[l].push_back(make_pair(1, make_pair(c, p)));
    g[r + 1].push_back(make_pair(-1, make_pair(c, p)));
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (auto& xx : g[i]) {
      upd(1, 0, N - 1, xx.second.second, xx.second.first * xx.first);
    }
    ans += get(1, 0, N - 1, k);
  }
  cout << ans;
  return 0;
}
