public class Euler460 {

    static double solveFast(int d, int window, double radialEps) {
        int w = d / 2;
        int h = w;
        double inf = Double.POSITIVE_INFINITY;

        double[][] g = new double[h + 1][w + 1];
        for (int i = 0; i <= h; i++) {
            for (int j = 0; j <= w; j++) {
                g[i][j] = inf;
            }
        }
        g[1][0] = 0.0;

        double[] logY = new double[h + 1];
        for (int y = 1; y <= h; y++) {
            logY[y] = Math.log(y);
        }

        int[] xRef = new int[h + 1];
        for (int y = 1; y <= h; y++) {
            int inner = w * w - y * y;
            xRef[y] = w - (int) Math.sqrt(inner);
        }

        int[][] sourceY = new int[w][];
        double outer2 = (w + radialEps) * (w + radialEps);
        double innerR = Math.max(0.0, w - radialEps);
        double inner2 = innerR * innerR;

        for (int x0 = 0; x0 < w; x0++) {
            double dx = w - x0;
            double dx2 = dx * dx;
            double low = inner2 - dx2;
            double high = outer2 - dx2;
            if (high < 1.0) {
                sourceY[x0] = new int[0];
                continue;
            }

            int yLo = Math.max(1, (int) Math.ceil(Math.sqrt(Math.max(0.0, low))));
            int yHi = Math.min(h, (int) Math.floor(Math.sqrt(Math.max(0.0, high))));
            if (yLo > yHi) {
                sourceY[x0] = new int[0];
                continue;
            }

            int[] temp = new int[yHi - yLo + 1];
            int count = 0;
            for (int y0 = yLo; y0 <= yHi; y0++) {
                double r = Math.sqrt(dx2 + (double) y0 * y0);
                if (Math.abs(r - w) <= radialEps + 1e-12) {
                    temp[count++] = y0;
                }
            }
            int[] ys = new int[count];
            System.arraycopy(temp, 0, ys, 0, count);
            sourceY[x0] = ys;
        }

        double bestHalf = inf;

        for (int x0 = 0; x0 < w; x0++) {
            int[] ys = sourceY[x0];
            for (int y0 : ys) {
                double base = g[y0][x0];
                if (!Double.isFinite(base))
                    continue;

                for (int y = y0; y <= h; y++) {
                    int dy = y - y0;
                    double invV = (dy == 0) ? 1.0 / y0 : (logY[y] - logY[y0]) / dy;

                    int xr = xRef[y];
                    int lx = Math.max(x0, xr - window);
                    int rx = Math.min(w, xr + 1);

                    double[] gy = g[y];
                    for (int x = lx; x <= rx; x++) {
                        int dx = x - x0;
                        double len = Math.sqrt(dx * dx + dy * dy) * invV;
                        double cand = base + len;
                        if (cand < gy[x]) {
                            gy[x] = cand;
                            if (x == w && cand < bestHalf) {
                                bestHalf = cand;
                            }
                        }
                    }
                }
            }
        }

        return 2.0 * bestHalf;
    }

    public static String solve() {
        double ans = solveFast(10000, 30, 0.5);
        return String.format(java.util.Locale.US, "%.9f", ans);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
