#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
mt19937 rng(228322420);
uniform_int_distribution<ll> urng(INT32_MIN, INT32_MAX);
ll n, k, m;
vector<ll> c, p;
struct event {
  ll x;
  ll type, id;
  bool operator<(const event &o) const {
    if (x != o.x) return x < o.x;
    return type < o.type;
  }
};
struct Key {
  ll price, amount;
  ll delta;
  bool operator<(const Key &o) const {
    if (price != o.price) return price < o.price;
    if (amount != o.amount) return amount < o.amount;
    return delta < o.delta;
  }
};
struct Node {
  Node *l, *r;
  Key key;
  ll prio;
  ll sum_price;
  ll sum;
};
Node null_node;
Node *null_v = &null_node;
Node *root = null_v;
void nupdate(Node *n) {
  n->sum_price =
      n->key.amount * n->key.price + n->l->sum_price + n->r->sum_price;
  n->sum = n->key.amount + n->l->sum + n->r->sum;
}
void nsplit(Node *n, Key x, Node *&l, Node *&r) {
  if (n == null_v) {
    l = r = null_v;
    return;
  }
  Node *tl, *tr;
  if (n->key < x) {
    nsplit(n->r, x, tl, tr);
    n->r = tl;
    l = n;
    r = tr;
  } else {
    nsplit(n->l, x, tl, tr);
    n->l = tr;
    l = tl;
    r = n;
  }
  nupdate(l);
  nupdate(r);
};
void nsplit2(Node *n, ll x, Node *&l, Node *&r) {
  if (n == null_v) {
    l = r = null_v;
    return;
  }
  Node *tl, *tr;
  ll s = n->l->sum + n->key.amount;
  if (x >= s) {
    nsplit2(n->r, x - s, tl, tr);
    n->r = tl;
    l = n;
    r = tr;
  } else {
    nsplit2(n->l, x, tl, tr);
    n->l = tr;
    l = tl;
    r = n;
  }
  nupdate(l);
  nupdate(r);
};
Node *nmerge(Node *a, Node *b) {
  if (a == null_v) return b;
  if (b == null_v) return a;
  if (a->prio < b->prio) {
    a->r = nmerge(a->r, b);
    nupdate(a);
    return a;
  } else {
    b->l = nmerge(a, b->l);
    nupdate(b);
    return b;
  }
}
void ninsert(Key val) {
  Node *n = root;
  Node *tl, *tr;
  nsplit(root, val, tl, tr);
  n = new Node;
  n->l = null_v;
  n->r = null_v;
  n->key = val;
  n->prio = urng(rng);
  nupdate(n);
  root = nmerge(nmerge(tl, n), tr);
}
void nerase(Key val) {
  Node *l, *r;
  nsplit(root, val, l, r);
  Node *l1, *r1;
  val.delta++;
  nsplit(r, val, l1, r1);
  val.delta--;
  root = nmerge(l, r1);
}
int main() {
  null_v->l = null_v->r = null_v;
  null_v->sum = 0;
  null_v->sum_price = 0;
  cin >> n >> k >> m;
  c.resize(m);
  p.resize(m);
  vector<event> e;
  for (ll i = 0; i < (ll)m; ++i) {
    ll l, r;
    cin >> l >> r >> p[i] >> c[i];
    e.push_back(event{l, 0, i});
    e.push_back(event{r + 1, 1, i});
  }
  sort(e.begin(), e.end());
  ll ans = 0;
  ll last = 0;
  for (auto &E : e) {
    if (last != 0) {
      ll d = E.x - last;
      if (root->sum < k) {
        ans += root->sum_price * d;
      } else {
        Node *l, *r;
        nsplit2(root, k - 1, l, r);
        ans += l->sum_price * d;
        ll left = k - l->sum;
        Node *t = r;
        while (t->l != null_v) t = t->l;
        ans += left * t->key.price * d;
        root = nmerge(l, r);
      }
    }
    last = E.x;
    if (E.type == 0) {
      ninsert(Key{c[E.id], p[E.id], E.id});
    } else {
      nerase(Key{c[E.id], p[E.id], E.id});
    }
  }
  ll d = n - last;
  if (root->sum < k) {
    ans += root->sum_price * d;
  } else {
    Node *l, *r;
    nsplit2(root, k - 1, l, r);
    ans += l->sum_price * d;
    ll left = k - l->sum;
    Node *t = r;
    while (t->l != null_v) t = t->l;
    ans += left * t->key.price * d;
    root = nmerge(l, r);
  }
  cout << ans << endl;
  return 0;
}
