#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n';
  err(++it, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, h, m;
  cin >> n >> h >> m;
  vector<int> x(n, h);
  for (int i = 0; i < m; i++) {
    int l, r, w;
    cin >> l >> r >> w;
    l--;
    r--;
    for (int i = l; i < r + 1; i++) x[i] = min(x[i], w);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) ans += (x[i] * x[i]);
  cout << ans << endl;
  return 0;
}
