#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const double EPS=1e-8;

inline double f(double a,double p,double q,double x){
	return a*(x-p)*(x-p)+q;
}

double parabola_perimeter(double a,double b,double c,double x1,double x2){
	x1+=b/(2*a);
	x2+=b/(2*a);
	double A=1/(4*a*a);
	return abs(a)*((x2*sqrt(x2*x2+A)+A*log(2*(sqrt(x2*x2+A)+x2)))
				  -(x1*sqrt(x1*x1+A)+A*log(2*(sqrt(x1*x1+A)+x1))));
}

int main(){
	int W,n; scanf("%d%*d%d",&W,&n);
	int a[50],p[50],q[50];
	rep(i,n) scanf("%d%d%d",a+i,p+i,q+i);

	vector<double> X;
	X.push_back(0);
	X.push_back(W);
	rep(i,n){
		// 山 i と窓枠の下辺との交点
		double cx=sqrt(-1.0*q[i]/a[i]);
		if(-EPS<p[i]-cx && p[i]-cx<W+EPS) X.push_back(p[i]-cx);
		if(-EPS<p[i]+cx && p[i]+cx<W+EPS) X.push_back(p[i]+cx);

		rep(j,i){ // 山 i と山 j の交点
			ll A=a[i]-a[j];
			ll B=-2*a[i]*p[i]+2*a[j]*p[j];
			ll C=a[i]*p[i]*p[i]+q[i]-a[j]*p[j]*p[j]-q[j];

			if(A!=0){ // Ax^2+Bx+C=0
				if(B*B-4*A*C>=0){
					double x;
					x=(-B-sqrt(B*B-4*A*C))/(2*A);
					if(-EPS<x && x<W+EPS) X.push_back(x);
					x=(-B+sqrt(B*B-4*A*C))/(2*A);
					if(-EPS<x && x<W+EPS) X.push_back(x);
				}
			}
			else if(B!=0){ // Bx+C=0
				double x=-1.0*C/B;
				if(-EPS<x && x<W+EPS) X.push_back(x);
			}
		}
	}

	sort(X.begin(),X.end());

	double ans=0;
	rep(i,(int)X.size()-1){
		double x1=X[i],x2=X[i+1];

		int j0=-1;
		rep(j,n){
			if(f(a[j],p[j],q[j],(x1+x2)/2)>0
			&& (j0==-1 || f(a[j0],p[j0],q[j0],(x1+x2)/2)<f(a[j],p[j],q[j],(x1+x2)/2))){
				j0=j;
			}
		}

		if(j0!=-1) ans+=parabola_perimeter(a[j0],-2*a[j0]*p[j0],p[j0]*p[j0]+q[j0],x1,x2);
	}

	printf("%.9f\n",ans);

	return 0;
}