#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-10;
int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
mt19937 rnd(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
long long a[maxm], pp[maxm];
long long getsum(int x) {
  long long sum = 0;
  for (int i = x; i > 0; i -= ((i) & (-i))) sum += a[i];
  return sum;
}
long long getsump(int x) {
  long long sum = 0;
  for (int i = x; i > 0; i -= ((i) & (-i))) sum += pp[i];
  return sum;
}
int n, k, m;
struct Node {
  int l, r, c, p;
  bool operator<(const Node& x) const { return r > x.r; }
} node[maxn];
bool cmp(Node& x, Node& y) { return x.l < y.l; }
priority_queue<Node> q;
void update(int x, long long v, long long p) {
  for (int i = x; i <= (int)1e6; i += ((i) & (-i))) {
    a[i] += v;
    pp[i] += v * p;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i += 1)
    cin >> node[i].l >> node[i].r >> node[i].c >> node[i].p;
  sort(node + 1, node + 1 + m, cmp);
  int j = 1;
  long long res = 0;
  for (int i = 1; i <= n; i += 1) {
    while (j <= m && node[j].l <= i) {
      q.push(node[j]);
      update(node[j].p, node[j].c, node[j].p);
      j += 1;
    }
    while (!q.empty() && q.top().r < i) {
      Node x = q.top();
      update(x.p, -x.c, x.p);
      q.pop();
    }
    int l = 1, r = 1e6;
    long long ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (getsum(mid) >= k) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    if (ans > 1)
      res += (k - getsum(ans - 1)) * ans + getsump(ans - 1);
    else if (ans == 0)
      res += getsump(1e6);
    else
      res += k;
  }
  cout << res;
  return ~~(0 - 0);
}
