#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <cstdio>
using namespace std;
typedef complex<double> P;

#define double long double

struct Par {
  double a,b,c;
  double func(double x) {
    return a*x*x + b*x + c;
  }
  double integral(double x) {
    double X = 2*a*x+b;

    double Y = log(X + sqrt(1+X*X));
    // double theta = atan(X);
    // Y = log(abs(1+sin(theta))/abs(1-sin(theta)))/2;
    
    double res = (X*sqrt(X*X+1) + Y) * 0.5;
    res /= 2*a;
//    cout << res << endl;
    return res;
  }
  double integral(double x1, double x2) {
    // double res = 0;
    // for (double x = x1; x<x2; x += 0.0001) {
    //   P p(x,func(x));
    //   P q(x+0.0001, func(x+0.0001));
    //   res += abs(p-q);
    // }
    // return res;
    return integral(x2) - integral(x1);
  }
};
Par par[100];

const double EPS = 1e-10;

vector<double> crosspoint(const Par &p, const Par &q) {
  double A = p.a-q.a;
  double B = p.b-q.b;
  double C = p.c-q.c;
  vector<double> res;
  if (abs(A) < EPS) {
    if (abs(B) < EPS) {
      return res;
    }
    res.push_back(-C/B);
    return res;
  }
  
  double D = B*B - 4*A*C;
  if (D < 0) {
    return res;
  }
  res.push_back((-B+sqrt(D))/(2*A));
  if (D > EPS) {
    res.push_back((-B-sqrt(D))/(2*A));
  }
  return res;
}


int main() {
  double w,h;
  int n;
  while(cin>>w>>h>>n) {
    for (int i = 0;i<n; ++i) {
      double a,p,q;
      cin >> a >> p >> q;
      double b = -2*a*p;
      double c = a*p*p + q;
      par[i] = (Par){a,b,c};
    }
    par[n] = (Par){0,0,0};
    
    vector<double> xs;
    xs.push_back(0);
    xs.push_back(w);
    for (int i=0; i<n; ++i) {
      for (int j=0; j<=n; ++j) {
        if (i == j) continue;
        vector<double> r = crosspoint(par[i],par[j]);
        for (int k=0; k<r.size(); ++k) {
          double x = r[k];
          if (x <= 0 || x >= w) continue;    
          xs.push_back(x);
        }
      }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    double ans = 0;
    for (int i=0; i<xs.size()-1; ++i) {
      double x1 = xs[i];
      double x2 = xs[i+1];
      double xm = (x1+x2)/2;
      double y_max = 0;
      int id = -1;
      for (int j=0; j<n; ++j) {
        double y = par[j].func(xm);
        if (y_max < y) {
          y_max = y;
          id = j;
        }
      }
      // cout << x1 << " " << x2 << " " << id << endl;
      if (id != -1)
        ans += par[id].integral(x1,x2);
    }
    printf("%.20Lf\n", ans);
  }
}