Problem: Two neighbours, Alan and Bob, live in the city, where there are three buildings only: a cinema, a shop and the house, where they live. The rest is a big asphalt square. 

Once they went to the cinema, and the film impressed them so deeply, that when they left the cinema, they did not want to stop discussing it.

Bob wants to get home, but Alan has to go to the shop first, and only then go home. So, they agreed to cover some distance together discussing the film (their common path might pass through the shop, or they might walk circles around the cinema together), and then to part each other's company and go each his own way. After they part, they will start thinking about their daily pursuits; and even if they meet again, they won't be able to go on with the discussion. Thus, Bob's path will be a continuous curve, having the cinema and the house as its ends. Alan's path — a continuous curve, going through the shop, and having the cinema and the house as its ends.

The film ended late, that's why the whole distance covered by Alan should not differ from the shortest one by more than t1, and the distance covered by Bob should not differ from the shortest one by more than t2.

Find the maximum distance that Alan and Bob will cover together, discussing the film.

Input

The first line contains two integers: t1, t2 (0 ≤ t1, t2 ≤ 100). The second line contains the cinema's coordinates, the third one — the house's, and the last line — the shop's. 

All the coordinates are given in meters, are integer, and do not exceed 100 in absolute magnitude. No two given places are in the same building.

Output

In the only line output one number — the maximum distance that Alan and Bob will cover together, discussing the film. Output the answer accurate to not less than 4 decimal places.

Examples

Input

0 2
0 0
4 0
-3 0


Output

1.0000000000


Input

0 0
0 0
2 0
1 0


Output

2.0000000000

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class MainD {

    private FastScanner in;
    private PrintWriter out;

    private static double EPS = 0.00000000001;

    public void solve() throws IOException {
        int diffPathPetya = in.nextInt();
        int diffPathVasya = in.nextInt();
        Point C = new Point(in.nextInt(), in.nextInt());
        Point H = new Point(in.nextInt(), in.nextInt());
        Point S = new Point(in.nextInt(), in.nextInt());
        double CH = C.distance(H);
        double CS = C.distance(S);
        double SH = S.distance(H);

        double maxPathPetyaS = diffPathPetya + CS;
        double maxPathVasyaH = diffPathVasya + CH;

        if (CS + SH <= maxPathVasyaH + EPS) {
            out.println(Math.min(maxPathVasyaH, maxPathPetyaS + SH));
            return;
        }

        if (SH <= maxPathPetyaS - maxPathVasyaH + EPS) {
            out.println(maxPathVasyaH);
            return;
        }

        double minTogether = diffPathPetya + diffPathVasya;
        minTogether = minTogether / 2;
        double maxTogether = Math.min(maxPathVasyaH, maxPathPetyaS);
        while (Math.abs(minTogether - maxTogether) > EPS) {
            double together = (minTogether + maxTogether) / 2;
            double vasyaAlone = maxPathVasyaH - together;
            double petyaAlone = maxPathPetyaS - together;
            boolean b1 = threeCirclesIntersect(new Circle(H, vasyaAlone),
                            new Circle(S, petyaAlone), new Circle(C, together));
            boolean b2 = threeCirclesIntersect(new Circle(S, petyaAlone),
                            new Circle(C, together), new Circle(H, vasyaAlone));
            boolean b3 = threeCirclesIntersect(new Circle(C, together),
                            new Circle(H, vasyaAlone),
                            new Circle(S, petyaAlone));
            if (b1 || b2 || b3) {
                minTogether = together;
            }
            else {
                maxTogether = together;
            }
        }

        out.println(minTogether);
    }

    private boolean threeCirclesIntersect(Circle circle1, Circle circle2,
                    Circle circle3) {
        Point center3 = circle3.getCenter();
        double radius3 = circle3.getRadius();
        List<GeometricObject> intersection = circle1.intersect(circle2);
        if (intersection.size() == 0) {
            return false;
        }
        if (intersection.size() == 1) {
            return center3.distance((Point) intersection.get(0)) < radius3
                            + EPS;
        }
        Point point1 = (Point) intersection.get(0);
        Point point2 = (Point) intersection.get(1);
        double dist = Math.min(center3.distance(point1),
                        center3.distance(point2));
        if (dist < radius3 + EPS) {
            return true;
        }
        boolean isIn1 = center3.distance(circle1.getCenter()) < circle1
                        .getRadius() + EPS;
        boolean isIn2 = center3.distance(circle2.getCenter()) < circle2
                        .getRadius() + EPS;
        if (isIn1 && isIn2) {
            return true;
        }
        if (!isIn1 && !isIn2) {
            return dist < radius3 + EPS;
        }
        if (isIn1) {
            Circle temp = circle1;
            circle1 = circle2;
            circle2 = temp;
        }

        double angle1 = Math.atan2(point1.getY() - circle1.getCenter().getY(),
                        point1.getX() - circle1.getCenter().getX());
        double angle2 = Math.atan2(point2.getY() - circle1.getCenter().getY(),
                        point2.getX() - circle1.getCenter().getX());
        if ((angle2 - angle1 + Math.PI * 4) % (2 * Math.PI) > Math.PI) {
            double temp = angle1;
            angle1 = angle2;
            angle2 = temp;
        }
        if (angle2 < angle1) {
            angle2 += Math.PI * 2;
        }

        double angle = Math.atan2(center3.getY() - circle1.getCenter().getY(),
                        center3.getX() - circle1.getCenter().getX());

        if (angle < angle1) {
            angle2 += Math.PI * 2;
        }

        if (angle > angle1 - EPS && angle < angle2 + EPS) {
            return circle1.getCenter().distance(center3) < circle1.getRadius()
                            + radius3 + EPS;
        }
        else {
            return dist < radius3 + EPS;
        }
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
            solve();
            out.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] arg) {
        new MainD().run();
    }
}

abstract class GeometricObject {

    public final static double EPS = 0.00000000001;

    public abstract void shift(double dx, double dy);

    public abstract void rotate(double angleDegreeCcw);

    public void rotate(Point pivot, double angleDegreeCcw) {
        shift(-pivot.getX(), -pivot.getY());
        rotate(angleDegreeCcw);
        shift(pivot.getX(), pivot.getY());
    }

    public abstract List<GeometricObject> intersect(GeometricObject otherObject);
}

class Point extends GeometricObject implements Comparable<Point> {

    private double x;
    private double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Point(Point p) {
        x = p.x;
        y = p.y;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    @Override
    public void shift(double dx, double dy) {
        x += dx;
        y += dy;
    }

    @Override
    public void rotate(double angleDegreeCcw) {
        double length = Math.sqrt(y * y + x * x);
        double currentAngle = Math.atan2(y, x) * 180.0 / Math.PI;
        currentAngle += angleDegreeCcw;
        currentAngle = currentAngle * Math.PI / 180;
        x = length * Math.cos(currentAngle);
        y = length * Math.sin(currentAngle);
    }

    @Override
    public void rotate(Point pivot, double angleDegreeCcw) {
        shift(-pivot.getX(), -pivot.getY());
        rotate(angleDegreeCcw);
        shift(pivot.getX(), pivot.getY());
    }

    @Override
    public List<GeometricObject> intersect(GeometricObject otherObject) {
        List<GeometricObject> result = new ArrayList<GeometricObject>();
        if (otherObject instanceof Point) {
            if (this.equals(otherObject)) {
                result.add(new Point(this));
            }
        }
        else {
            return otherObject.intersect(this);
        }
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Point) {
            Point otherPoint = (Point) obj;
            return (Math.abs(x - otherPoint.x) < EPS)
                            && (Math.abs(y - otherPoint.y) < EPS);
        }
        else {
            return false;
        }
    }

    public double squareDistance(Point otherPoint) {
        return (x - otherPoint.x) * (x - otherPoint.x) + (y - otherPoint.y)
                        * (y - otherPoint.y);
    }

    public double distance(Point otherPoint) {
        return Math.sqrt(squareDistance(otherPoint));
    }

    @Override
    public int compareTo(Point otherPoint) {
        if (x < otherPoint.x - EPS
                        || (Math.abs(x - otherPoint.x) < EPS && y < otherPoint.y
                                        - EPS)) {
            return -1;
        }
        else if (this.equals(otherPoint)) {
            return 0;
        }
        else {
            return 1;
        }
    }

    @Override
    public int hashCode() {
        return (int) ((x * 31 + y) * 10000);
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }

}

class Hyperbola {

    private double a2;
    private double b2;

    Hyperbola(double a2, double b2) {
        this.a2 = a2;
        this.b2 = b2;
    }

    double value(Point p) {
        return p.getX() * p.getX() / a2 - p.getY() * p.getY() / b2;
    }
}

class Line extends GeometricObject {

    private double A;
    private double B;
    private double C;

    public Line(double A, double B, double C) {
        if (A == 0 && B == 0) {
            throw new IllegalArgumentException(
                            "Can't create line. A and B = 0.");
        }
        this.A = A;
        this.B = B;
        this.C = C;
        normalize();
    }

    public Line(Line line) {
        this(line.A, line.B, line.C);
    }

    private void normalize() {
        double p = Math.sqrt(A * A + B * B);
        A /= p;
        B /= p;
        C /= p;
        if (A < 0) {
            A = -A;
            B = -B;
            C = -C;
        }
        else if (A == 0 && B < 0) {
            B = -B;
            C = -C;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Line) {
            Line line = (Line) obj;
            return (Math.abs(A - line.getA()) < EPS)
                            && (Math.abs(B - line.getB()) < EPS)
                            && (Math.abs(C - line.getC()) < EPS);
        }
        else {
            return false;
        }
    }

    public static Line fromPoints(Point a, Point b) {
        if (a.equals(b)) {
            throw new IllegalArgumentException(
                            "Can't define line. Points are equal.");
        }
        double A = a.getY() - b.getY();
        double B = b.getX() - a.getX();
        double C = a.getX() * b.getY() - a.getY() * b.getX();
        return new Line(A, B, C);
    }

    public double getC() {
        return C;
    }

    public double getA() {
        return A;
    }

    public double getB() {
        return B;
    }

    public boolean isPointOnLine(Point p) {
        return Math.abs(A * p.getX() + B * p.getY() + C) < EPS;
    }

    @Override
    public void shift(double dx, double dy) {
        C = C - B * dy - A * dx;
    }

    @Override
    public void rotate(double angleDegreeCcw) {
        Point p1;
        Point p2;
        if (A == 0) {
            p1 = new Point(0, -C / B);
            p2 = new Point(1, -C / B);
        }
        else {
            p1 = new Point(-C / A, 0);
            p2 = new Point((-C - B) / A, 1);
        }
        p1.rotate(angleDegreeCcw);
        p2.rotate(angleDegreeCcw);
        Line newLine = Line.fromPoints(p1, p2);
        A = newLine.getA();
        B = newLine.getB();
        C = newLine.getC();
    }

    @Override
    public List<GeometricObject> intersect(GeometricObject otherObject) {
        return null;
    }

    public double pointShift(Point a) {
        double result = A * a.getX() + B * a.getY() + C;
        if (Math.abs(result) < EPS) {
            result = 0;
        }
        return result;
    }

    public double distanceToPoint(Point a) {
        return Math.abs(pointShift(a));
    }

    public boolean isParallel(Line otherLine) {
        return Math.abs(A * otherLine.getB() - B * otherLine.getA()) < EPS;
    }
}

class Circle extends GeometricObject {

    private Point center;
    private double radius;

    public Circle(Point center, double radius) {
        this.center = new Point(center);
        this.radius = radius;
    }

    public Circle(Circle circle) {
        this(circle.center, circle.radius);
    }

    public Point getCenter() {
        return new Point(center);
    }

    public double getRadius() {
        return radius;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Circle)) {
            return false;
        }
        Circle otherCircle = (Circle) obj;
        return otherCircle.center.equals(center)
                        && Math.abs(radius - otherCircle.radius) < EPS;
    }

    @Override
    public void shift(double dx, double dy) {
        center.shift(dx, dy);
    }

    @Override
    public void rotate(double angleDegreeCcw) {
        center.rotate(angleDegreeCcw);
    }

    @Override
    public List<GeometricObject> intersect(GeometricObject otherObject) {
        List<GeometricObject> result = new ArrayList<GeometricObject>();
        if (otherObject instanceof Point) {
            if (Math.abs(center.distance((Point) otherObject) - radius) < EPS) {
                result.add(otherObject);
            }
        }
        else if (otherObject instanceof Line) {
            result.addAll(LineCircleIntersection.findIntersection(
                            (Line) otherObject, this));
        }
        else if (otherObject instanceof Circle) {
            return CirclesIntersection.findIntersection(this,
                            (Circle) otherObject);
        }
        else {
            return otherObject.intersect(this);
        }

        return result;
    }
}

class CirclesIntersection {

    public static List<GeometricObject> findIntersection(Circle circle1,
                    Circle circle2) {
        circle1 = new Circle(circle1);
        circle2 = new Circle(circle2);
        if (circle1.getCenter().equals(circle2.getCenter())) {
            List<GeometricObject> result = new ArrayList<GeometricObject>();
            if (circle1.equals(circle2)) {
                result.add(circle1);
            }
            return result;
        }
        else {
            double dx = circle1.getCenter().getX();
            double dy = circle1.getCenter().getY();
            circle1.shift(-dx, -dy);
            circle2.shift(-dx, -dy);
            double x = circle2.getCenter().getX();
            double y = circle2.getCenter().getY();
            double A = -2 * x;
            double B = -2 * y;
            double C = x * x + y * y + Math.pow(circle1.getRadius(), 2)
                            - Math.pow(circle2.getRadius(), 2);
            Line line = new Line(A, B, C);
            List<GeometricObject> result = new ArrayList<GeometricObject>();
            for (Point p : LineCircleIntersection.findIntersection(line,
                            circle1)) {
                p.shift(dx, dy);
                result.add(p);
            }
            return result;
        }
    }
}

class LineCircleIntersection {

    private static double EPS = 0.00000000001;

    public static List<Point> findIntersection(Line line, Circle circle) {
        List<Point> result = new ArrayList<Point>();
        line = new Line(line);
        circle = new Circle(circle);
        Point center = circle.getCenter();
        double dx = center.getX();
        double dy = center.getY();

        line.shift(-dx, -dy);
        circle.shift(-dx, -dy);

        double rad = circle.getRadius();
        double d = line.distanceToPoint(new Point(0, 0));
        if (d > rad + EPS) {
            return result;
        }

        double A = line.getA();
        double B = line.getB();
        double C = line.getC();
        double r = A * A + B * B;
        Point D = new Point(-A * C / r, -B * C / r);
        if (Math.abs(d - circle.getRadius()) < EPS) {
            D.shift(dx, dy);
            result.add(D);
            return result;
        }

        double f = Math.sqrt(rad * rad - d * d);
        double mult = Math.sqrt(f * f / r);

        result.add(new Point(D.getX() + B * mult, D.getY() - A * mult));
        result.add(new Point(D.getX() - B * mult, D.getY() + A * mult));
        result.get(0).shift(dx, dy);
        result.get(1).shift(dx, dy);
        return result;
    }
}