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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// floating
typedef long double Real;
const Real EPS = 1e-9;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int T,n;
int x[125252], l[125252], h[125252];

int main(){
  scanf("%d%d",&T,&n);
  REP(i,n)scanf("%d%d%d",x+i,l+i,h+i);
  Real ans = 0.0;
  
  Real minimum = T / 2.0;
  // DEBUG(minimum);
  typedef pair<Real,Real> prr;

  // 1. find max low > minimum, fly at v^2 = low (high desc order)
  set<prr> S1, S2;
  REP(i,n){
    Real X = x[i];
    Real L = l[i];
    Real H = h[i];
    Real low = X*(T-X) / (2.0*H);
    Real high = X*(T-X) / (2.0*L);
    // printf("low: %.18Lf, high: %.18Lf\n",low,high);
    S1.insert(prr(low,high));
    S2.insert(prr(high,low));
  }
  while(S1.size()){
    prr P1 = *S1.rbegin();
    Real p = P1.first;
    if(p < minimum+EPS)break;
    // printf("1. %.18Lf\n",p);
    ans += sqrt(p + 0.25*T*T/p);
    S1.erase(P1);
    S2.erase(prr(P1.second, P1.first));
    while(S2.size()){
      prr P2 = *S2.rbegin();
      Real low = P2.second;
      Real high = P2.first;
      if(p <= high+EPS){
        S1.erase(prr(low,high));
        S2.erase(prr(high,low));
      }else{
        break;
      }
    }
  }

  // 2. find min high < minimum, fly at v^2 = high (low asc order)
  while(S2.size()){
    prr P2 = *S2.begin();
    Real p = P2.first;
    if(p > minimum-EPS)break;
    // printf("2. %.18Lf\n",p);
    ans += sqrt(p + 0.25*T*T/p);
    S2.erase(P2);
    S1.erase(prr(P2.second, P2.first));
    while(S1.size()){
      prr P1 = *S1.begin();
      Real low = P1.first;
      Real high = P1.second;
      if(p >= low-EPS){
        S1.erase(prr(low,high));
        S2.erase(prr(high,low));
      }else{
        break;
      }
    }
  }

  // 3. assert low <= minimum <= high, fly at v^2 = minimum
  if(S1.size()){
    Real p = minimum;
    ans += sqrt(p + 0.25*T*T/p);
    // printf("3. %.18Lf\n",p);
  }

  printf("%.18Lf\n", ans);

  return 0;
}

