#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647, nmax = 400005;
const long long Inf = 9223372036854775807ll;
const string file = "";
struct server {
  long long l, r, n, p;
  bool operator<(const server &obj) const { return p < obj.p; }
};
struct ev {
  long long t, tip, p;
  bool operator<(const ev &obj) const {
    if (t != obj.t) return t < obj.t;
    return tip < obj.tip;
  }
};
long long n, w, m, aint[nmax * 4], aint2[nmax * 4];
server v[nmax];
ev e[nmax];
bool ok[nmax];
vector<ev> a[1000006];
void flip(long long pos, long long nod = 1, long long st = 1,
          long long dr = m) {
  if (st == dr) {
    ok[st] = 1 - ok[st];
    if (aint[nod] != 0) {
      aint[nod] = 0;
      aint2[nod] = 0;
    } else {
      aint[nod] = 1ll * v[st].p * v[st].n;
      aint2[nod] = v[st].n;
    }
  } else {
    long long mid = (st + dr) / 2;
    if (mid >= pos)
      flip(pos, nod * 2, st, mid);
    else
      flip(pos, nod * 2 + 1, mid + 1, dr);
    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];
    aint2[nod] = aint2[nod * 2] + aint2[nod * 2 + 1];
  }
}
long long query(long long need = w, long long nod = 1, long long st = 1,
                long long dr = m) {
  if (aint2[nod] <= need) return aint[nod];
  if (ok[dr] && aint2[nod] - v[dr].n <= need)
    return aint[nod] + 1ll * (need - aint2[nod]) * v[dr].p;
  long long mid = (st + dr) / 2;
  if (aint2[nod * 2] >= need) return query(need, nod * 2, st, mid);
  return query(need, nod * 2, st, mid) +
         query(need - aint2[nod * 2], nod * 2 + 1, mid + 1, dr);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> w >> m;
  for (long long i = 1; i <= m; ++i)
    cin >> v[i].l >> v[i].r >> v[i].n >> v[i].p;
  sort(v + 1, v + m + 1);
  for (long long i = 1; i <= m; ++i) {
    e[i * 2 - 1] = {v[i].l, 0, i};
    e[i * 2] = {v[i].r + 1, 1, i};
  }
  sort(e + 1, e + 2 * m + 1);
  for (int i = 1; i <= m * 2; ++i) {
    a[e[i].t].push_back(e[i]);
  }
  long long sol = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto x : a[i]) flip(x.p);
    sol += query();
  }
  cout << sol;
  return 0;
}
