#include <bits/stdc++.h>
using namespace std;
int n, h, m;
vector<int> l, r, x;
int main() {
  cin >> n >> h >> m;
  for (int i = 0; i < m; ++i) {
    int ll, rr, xx;
    cin >> ll >> rr >> xx;
    l.push_back(ll);
    r.push_back(rr);
    x.push_back(xx);
  }
  int geld = 0;
  for (int i = 1; i <= n; ++i) {
    int hoehe = h;
    for (int j = 0; j < m; ++j) {
      if (i >= l[j] && i <= r[j]) {
        if (x[j] < hoehe) {
          hoehe = x[j];
        }
      }
    }
    geld += hoehe * hoehe;
  }
  cout << geld;
  return 0;
}
