Problem: Problem

A dolphin who lives in a certain aquarium will be rewarded if he jumps and goes through the $ N $ ring.

* Dolphin jumps from coordinates $ (0,0) $ and lands at $ (T,0) $.
* The trajectory of the jump is a parabola.
* The $ i $ th ring is determined to have passed through when the jump trajectory intersects the line segment connecting $ (X_i, L_i) $ and $ (X_i, H_i) $.
* $ 1 $ jump requires as much physical strength as the initial velocity.



Dolphins can jump as many times as they want. Let the gravitational acceleration vector be $ (0, -1) $ and find the minimum total physical strength required for the dolphin to pass through all the rings. However, suppose friction and air resistance are negligibly small.

Constraints

The input satisfies the following conditions.

* All inputs are integers.
* $ 1 \ le X_i <T \ le 10 ^ 6 $
* $ 1 \ le N \ le 10 ^ 5 $
* $ 1 \ le L_i <H_i \ le 10 ^ 6 $

Input

The input is given in the following format.


$ T $ $ N $
$ X_1 $ $ L_1 $ $ H_1 $
$ \ vdots $
$ X_N $ $ L_N $ $ H_N $


First, $ T $ and $ N $ are given to the $ 1 $ line. Then the $ N $ line is given the position of the $ i $ th ring, $ X_i $, $ L_i $, and $ H_i $.

Output

Output the answer on one line. If the absolute error or relative error is $ 10 ^ {-9} $ or less, the answer is judged to be correct.

Examples

Input

100 5
50 1 5
50 5 10
50 20 30
50 40 60
50 61 1000000


Output

48.6090201099


Input

64 15
38 133177 927361
48 177920 668766
12 680425 790550
43 6853 384115
17 214954 723798
62 63843 153825
28 399349 482937
2 336136 367001
33 138008 733496
6 203462 911631
58 321974 527734
17 696940 781678
55 265874 507640
41 56037 880001
34 279422 528651


Output

6087.909851326286

Solution (in CPP):

Solution:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
using LD = long double;

const LD EPS = 1e-11;

LD T;
int N;

inline LD alpha(LD x, LD y) {
	return y / (x * (T - x));
}

inline LD tangle(LD x, LD y) {
	return alpha(x, y) * T;
}

inline LD cost(LD tilt) {
	return sqrt(T * (tilt * tilt + 1.) / (2 * tilt));
}

LD solve(const vector<pair<LD, LD>>&vec, LD& center) {
	LD res = 0.;
	set<LD>S;
	for (auto &elm : vec) {
		//ここ怪しいなあ、バグか？
		if (S.lower_bound(elm.first) == S.lower_bound(elm.second)) {
			res += elm.first;
			S.insert(elm.first);
			center = elm.first;
		}
	}
	return res;
}

int main(void)
{
	cin >> T >> N;
	bool is45 = false;
	vector<pair<LD, LD>>locos, hicos;
	vector<pair<LD, LD>>cencos;
	for (int i = 0; i < N; ++i) {
		LD X, L, H;
		cin >> X >> L >> H;
		LD lo = tangle(X, L);
		LD hi = tangle(X, H);
		if (lo <= 1. && hi >= 1.) {
			//45°線を通る
			is45 = true;
			cencos.push_back({ cost(lo) + EPS,cost(hi) + EPS });
			continue;
		}
		if (lo < 1. && hi < 1.) {
			//45°未満
			locos.push_back({ cost(hi) - EPS,cost(lo) + EPS });
		}
		else {
			//45°以上
			hicos.push_back({ cost(lo) - EPS,cost(hi) + EPS });
		}
	}
	LD ans = 0;
	sort(locos.rbegin(), locos.rend());
	sort(hicos.rbegin(), hicos.rend());
	LD locen = 1e18, hicen = 1e18;
	ans += solve(locos, locen);
	ans += solve(hicos, hicen);
	cout.precision(15);
	if (is45) {
		for (auto elm : cencos) {
			if (elm.first < locen && elm.second < hicen) {
				ans += sqrt(T);
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}