#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, m, h, l, r, x, a[1010];
char c;
string s;
vector<long long> q1;
map<long long, long long> q2;
set<long long> q3;
int main() {
  cin >> n >> h >> m;
  for (i = 1; i <= n; i++) {
    a[i] = h;
  }
  while (m--) {
    cin >> l >> r >> x;
    for (i = l; i <= r; i++) {
      a[i] = min(a[i], x);
    }
  }
  for (i = 1; i <= n; i++) {
    j += a[i] * a[i];
  }
  cout << j;
}
