#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, h, m;
  cin >> n >> h >> m;
  int l[m + 1], r[m + 1], x[m + 1];
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i] >> x[i];
  }
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    a[i] = h;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      a[j] = min(a[j], x[i]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i] * a[i];
  }
  cout << ans;
}
