#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, h, m;
  cin >> n >> h >> m;
  vector<int> arr(n + 1);
  for (int i = 0; i < n; i++) {
    arr[i] = h;
  }
  for (int i = 0; i < m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    for (int j = l - 1; j < r; j++) {
      arr[j] = (arr[j] > x ? x : arr[j]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += arr[i] * arr[i];
  }
  cout << ans << endl;
  return 0;
}
