#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
struct fastIO {
  fastIO() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
  }
} fio;
template <typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}
bool compare(vector<long long> a, vector<long long> b) { return b[2] > a[2]; }
long long minPossibleHeight(vector<vector<long long>> v, long long val,
                            long long maxH) {
  long long n = v.size();
  for (long long i = 0; i < n; i++) {
    long long l = v[i][0], r = v[i][1], x = v[i][2];
    if (l <= val && r >= val) {
      return x * x;
    }
  }
  return maxH * maxH;
}
void test_case() {
  long long n, h, m;
  read(n, h, m);
  vector<vector<long long>> v(m, vector<long long>(3));
  for (long long i = 0; i < m; i++) {
    read(v[i][0], v[i][1], v[i][2]);
  }
  sort(v.begin(), v.end(), compare);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += minPossibleHeight(v, i + 1, h);
  }
  cout << ans << "\n";
}
int32_t main() {
  long long T = 1;
  while (T--) {
    test_case();
  }
  return 0;
}
