#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, h, m;
  while (cin >> n >> h >> m) {
    long long i, j, l, r, x, ans = 0;
    long long arr[100];
    for (i = 1; i <= n; i++) arr[i] = h;
    for (i = 1; i <= m; i++) {
      cin >> l >> r >> x;
      for (j = l; j <= r; j++) arr[j] = min(arr[j], x);
    }
    for (i = 1; i <= n; i++) ans += (arr[i] * arr[i]);
    cout << ans << endl;
  }
}
