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