#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  map<int, int> mm;
  for (int i = 1; i <= n; ++i) mm[i] = h;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int j = a; j <= b; ++j) mm[j] = min(mm[j], c);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans += (mm[i] * mm[i]);
  cout << ans;
  return 0;
}
