Problem: Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. That's why he wants to find the shortest route from the excavation point to his crypt. Greg has recollected how the Codeforces participants successfully solved the problem of transporting his coffin to a crypt. So, in some miraculous way Greg appeared in your bedroom and asks you to help him in a highly persuasive manner. As usual, you didn't feel like turning him down.

After some thought, you formalized the task as follows: as the Neverland mountain has a regular shape and ends with a rather sharp peak, it can be represented as a cone whose base radius equals r and whose height equals h. The graveyard where Greg is busy excavating and his crypt can be represented by two points on the cone's surface. All you've got to do is find the distance between points on the cone's surface. 

The task is complicated by the fact that the mountain's base on the ground level and even everything below the mountain has been dug through by gnome (one may wonder whether they've been looking for the same stuff as Greg...). So, one can consider the shortest way to pass not only along the side surface, but also along the cone's base (and in a specific case both points can lie on the cone's base — see the first sample test)

Greg will be satisfied with the problem solution represented as the length of the shortest path between two points — he can find his way pretty well on his own. He gave you two hours to solve the problem and the time is ticking!

Input

The first input line contains space-separated integers r and h (1 ≤ r, h ≤ 1000) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in the systems of coordinates where the origin of coordinates is located in the centre of the cone's base and its rotation axis matches the OZ axis. In this coordinate system the vertex of the cone is located at the point (0, 0, h), the base of the cone is a circle whose center is at the point (0, 0, 0), lying on the XOY plane, and all points on the cone surface have a non-negative coordinate z. It is guaranteed that the distances from the points to the cone surface do not exceed 10 - 12. All real numbers in the input have no more than 16 digits after decimal point.

Output

Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10 - 6.

Examples

Input

2 2
1.0 0.0 0.0
-1.0 0.0 0.0


Output

2.000000000

Input

2 2
1.0 0.0 0.0
1.0 0.0 1.0


Output

2.414213562

Input

2 2
1.0 0.0 1.0
-1.0 0.0 1.0


Output

2.534324263

Input

2 2
1.0 0.0 0.0
0.0 1.0 1.0


Output

3.254470198

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
const long double pi = acosl(-1.);
const long double eps = 1e-11;
int r, h;
long double getAngle(long double x, long double y, long double z) {
  long double H = h - z;
  if (H < eps) return 0;
  long double R = r * H / h;
  long double X = 0;
  long double Y = R;
  long double d = sqrtl((x - X) * (x - X) + (y - Y) * (y - Y));
  long double a = asinl(d / 2 / R) * 2;
  long double l = a * R / sqrtl(R * R + H * H);
  if (x > 0) l = -l;
  return l;
}
long double conDist(long double z, long double Z, long double a) {
  long double r1 = sqrtl(h * h + r * r + 0.) / h * (h - z);
  long double r2 = sqrtl(h * h + r * r + 0.) / h * (h - Z);
  long double x = r1;
  long double y = 0;
  long double X = cosl(a) * r2;
  long double Y = sinl(a) * r2;
  return sqrtl((x - X) * (x - X) + (y - Y) * (y - Y));
}
long double getOnConus(long double x, long double y, long double z,
                       long double X, long double Y, long double Z) {
  long double a1 = getAngle(x, y, z);
  long double a2 = getAngle(X, Y, Z);
  long double a = fabsl(a2 - a1);
  long double A = r / sqrtl(h * h + r * r + 0.) * 2 * pi;
  return min(conDist(z, Z, a), conDist(z, Z, A - a));
}
long double getOnConus(long double x, long double y, long double z,
                       long double X, long double Y) {
  if (z > eps) return getOnConus(x, y, z, X, Y, 0);
  return sqrtl((x - X) * (x - X) + (y - Y) * (y - Y));
}
long double getD(long double x, long double y, long double z, long double X,
                 long double Y, long double Z, long double XX, long double YY,
                 long double XXX, long double YYY) {
  long double res = sqrtl((XX - XXX) * (XX - XXX) + (YY - YYY) * (YY - YYY));
  res += getOnConus(x, y, z, XX, YY);
  res += getOnConus(X, Y, Z, XXX, YYY);
  if (0)
    if (res < 1.6) {
      cout << x << ' ' << y << ' ' << z << " -> " << XX << ' ' << YY << " = "
           << getOnConus(x, y, z, XX, YY, 0) << endl;
      cout << X << ' ' << Y << ' ' << Z << " -> " << XXX << ' ' << YYY << " = "
           << getOnConus(X, Y, Z, XXX, YYY, 0) << endl;
      cout << res << ": "
           << sqrt((XX - XXX) * (XX - XXX) + (YY - YYY) * (YY - YYY)) << ' '
           << endl;
    }
  return res;
}
long double getD(long double x, long double y, long double z, long double X,
                 long double Y, long double Z, long double XX, long double YY) {
  long double res = 1e100;
  for (int i(0); i < (6); i++) {
    long double a = 2 * pi / 3 * i;
    long double b = a + pi;
    for (int j(0); j < (50); j++) {
      long double s1 = (a * 2 + b) / 3;
      long double s2 = (a + 2 * b) / 3;
      long double d1 =
          getD(x, y, z, X, Y, Z, XX, YY, cosl(s1) * r, sinl(s1) * r);
      long double d2 =
          getD(x, y, z, X, Y, Z, XX, YY, cosl(s2) * r, sinl(s2) * r);
      res = min(res, d1);
      res = min(res, d2);
      if (d1 < d2)
        b = s2;
      else
        a = s1;
    }
  }
  return res;
}
long double go(long double x, long double y, long double z, long double X,
               long double Y, long double Z) {
  long double res = getOnConus(x, y, z, X, Y, Z);
  if (z < eps || Z < eps) res = 1e100;
  for (int i(0); i < (6); i++) {
    long double a = 2 * pi / 3 * i;
    long double b = a + pi;
    for (int j(0); j < (50); j++) {
      long double s1 = (a * 2 + b) / 3;
      long double s2 = (a + 2 * b) / 3;
      long double d1 = getD(x, y, z, X, Y, Z, cosl(s1) * r, sinl(s1) * r);
      long double d2 = getD(x, y, z, X, Y, Z, cosl(s2) * r, sinl(s2) * r);
      res = min(res, d1);
      res = min(res, d2);
      if (d1 < d2)
        b = s2;
      else
        a = s1;
    }
  }
  return res;
}
int main() {
  cin >> r >> h;
  long double x, y, z, X, Y, Z;
  cin >> x >> y >> z >> X >> Y >> Z;
  if (z < eps && Z < eps)
    printf("%.10lf\n", (double)sqrt((x - X) * (x - X) + (y - Y) * (y - Y)));
  else
    printf("%.10lf\n", (double)go(x, y, z, X, Y, Z));
  return 0;
}