#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long fp(long long a, long long b) {
  if (b == 0) return 1;
  long long x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1) x = (x * a) % mod;
  return x;
}
long long sq(long long x) { return x * x; }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, h, x, l, r, ans = 0;
  cin >> n >> h >> m;
  vector<long long> v(n + 1, h);
  for (long long i = 1; i <= m; i++) {
    cin >> l >> r >> x;
    for (long long j = l; j <= r; j++) v[j] = min(v[j], x);
  }
  for (long long i = 1; i <= n; i++) ans += v[i] * v[i];
  cout << ans;
}
