#include <bits/stdc++.h>
using namespace std;
int pcnt, mxh, arrl, l, r, mxs, ma[300];
long long profit;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 1; i <= 100; i++) {
    ma[i] = -1;
  }
  cin >> pcnt >> mxh >> arrl;
  for (int i = 1; i <= arrl; i++) {
    cin >> l >> r >> mxs;
    for (int j = l; j <= r; j++) {
      if (ma[j] != -1) {
        ma[j] = min(ma[j], mxs);
      } else {
        ma[j] = mxs;
      }
    }
  }
  for (int i = 1; i <= pcnt; i++) {
    if (ma[i] == -1) {
      profit += mxh * mxh;
    } else {
      profit += ma[i] * ma[i];
    }
  }
  cout << profit;
}
