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