#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 2e18;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAXN = 2e5 + 3;
void solve() {
  long long n;
  cin >> n;
  long long h, m;
  cin >> h >> m;
  vector<long long> arr(n, h);
  while (m--) {
    long long l, r, x;
    cin >> l >> r >> x;
    --l, --r;
    for (long long i = l; i <= r; ++i) arr[i] = min(arr[i], x);
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i) ans += arr[i] * arr[i];
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
}
