#include <bits/stdc++.h>
using ll = long long;
const ll N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll SZ = 101;
const double eps = 1e-9;
using namespace std;
void solve() {
  ll n, h, m;
  cin >> n >> h >> m;
  vector<ll> a(n, h);
  for (ll(i) = 0; i < (m); i++) {
    ll l, r, x;
    cin >> l >> r >> x;
    for (ll i = (l - 1); i <= (r - 1); i++) {
      a[i] = min(a[i], x);
    }
  }
  ll ans = 0;
  for (ll(i) = 0; i < (n); i++) {
    ans += a[i] * a[i];
  }
  cout << ans;
}
int32_t main(int32_t argc, char *argv[]) {
  double t1 = clock();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll TC = 1, t = 0;
  while (t++ < TC) {
    solve();
  }
  if (false)
    cerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n";
  return 0;
}
