Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Cross Points of Circles

For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.

Input

The input is given in the following format.

$c1x\; c1y\; c1r$

$c2x\; c2y\; c2r$

$c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle.
$c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle.
All input values are given in integers.

Output

Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules.

If there is one cross point, print two coordinates with the same values.

Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.

The output values should be in a decimal fraction with an error less than 0.000001.

Constraints

The given circle have at least one cross point and have different center coordinates.

$-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$

$1 \leq c1r, c2r \leq 10,000$

Sample Input and Output

Sample Input 1

0 0 2
2 0 2

Sample Output 1

1.00000000 -1.73205080 1.00000000 1.73205080

Sample Input 2

0 0 2
0 3 1

Sample Output 2

0.00000000 2.00000000 0.00000000 2.00000000

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
//using System.Linq;
//using Vector = CGL.Point;
//using Line = CGL.Segment;
//using Polygon = System.Collections.Generic.List<CGL.Point>;

namespace CGL
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = scan;
            var c1 = new Circle(new Point(k[0], k[1]), k[2]);
            k = scan;
            var c2 = new Circle(new Point(k[0], k[1]), k[2]);

            var p = c1.GetCrossPoints(c2);
            if (p.Key<p.Value)
            {
                Console.WriteLine("{0:f7} {1:f7} {2:f7} {3:f7}",p.Key.x,p.Key.y,p.Value.x,p.Value.y);
            }
            else
            {
                Console.WriteLine("{0:f7} {1:f7} {2:f7} {3:f7}", p.Value.x, p.Value.y, p.Key.x, p.Key.y);
            }
        }
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
    
    struct Point
    {
        static readonly double EPS = 1E-10;
        public double x, y;
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public static Point operator +(Point a, Point b) { return new Point(a.x + b.x, a.y + b.y); }
        public static Point operator -(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); }
        public static Point operator *(Point a, double k) { return new Point(k * a.x, k * a.y); }
        public static Point operator /(Point a, double k) { return new Point(a.x / k, a.y / k); }
        
        public double Abs { get { return Math.Sqrt(Norm); } }  
        public double Norm { get { return x * x + y * y; } }
        public double Arg { get { return Math.Atan2(y, x); } }
        public double Dot(Point p) { return x * p.x + y * p.y; }
        public double Cross(Point p) { return x * p.y - y * p.x; }
        public double GetDistance(Point p) { return (this - p).Abs; }

        public static bool operator <(Point a, Point b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(Point a, Point b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(Point a, Point b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(Point a, Point b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public override bool Equals(object p){  return Math.Abs(x - ((Point)p).x) < EPS && Math.Abs(y - ((Point)p).y) < EPS; }
        public override int GetHashCode(){ return x.GetHashCode() ^ y.GetHashCode(); }

        public int CCW(Point b)
        {
            if (Cross(b) > EPS) return 1;
            if (Cross(b) < -EPS) return -1;
            if (Dot(b) < -EPS) return 2;
            if (Norm < b.Norm) return -2;
            return 0;
        }
    }
    struct Segment
    {
        public Point p1, p2;
        public Segment(Point p1, Point p2)
        {
            this.p1 = p1;
            this.p2 = p2;
        }
        public Point Projection(Point p)
        {
            Point b = p2 - p1;
            double r = b.Dot(p - p1) / b.Norm;
            return p1 + b * r;
        }
        public Point Reflection(Point p)
        {
            return p + (Projection(p) - p) * 2;
        }
        public double GetD_LP(Point p)
        {
            return Math.Abs((p - p1).Cross(p2 - p1) / (p2 - p1).Abs);
        }
        public double GetD_SP(Point p)
        {
            if ((p - p1).Dot(p2 - p1) < 0) return (p - p1).Abs;
            if ((p - p2).Dot(p1 - p2) < 0) return (p - p2).Abs;
            return GetD_LP(p);
        }
        public bool Intersect(Segment s)
        {
            return (p2 - p1).CCW(s.p1 - p1) * (p2 - p1).CCW(s.p2 - p1) <= 0 &&
                (s.p2 - s.p1).CCW(p1 - s.p1) * (s.p2 - s.p1).CCW(p2 - s.p1) <= 0;
        }
        public double GetDistance(Segment s)
        {
            if (this.Intersect(s)) return 0;
            return Math.Min(Math.Min(GetD_SP(s.p1), GetD_SP(s.p2)), Math.Min(s.GetD_SP(p1), s.GetD_SP(p2)));
        }
        public Point GetCrossPoint(Segment s)
        {
            Point b = s.p2 - s.p1;
            double d1 = Math.Abs(b.Cross(p1 - s.p1));
            double d2 = Math.Abs(b.Cross(p2 - s.p1));
            double t = d1 / (d1 + d2);
            return p1 + (p2 - p1) * t;
        }
    }
    struct Circle
    {
        public Point c; double r;
        public Circle(Point c, double r)
        {
            this.c = c;
            this.r = r;
        }
        public bool Intersect(Segment l)
        {
            return l.GetD_LP(c) <= r;
        }
        public KeyValuePair<Point, Point> GetCrossPoints(Segment l)
        {
            Point pr = l.Projection(c);
            Point e = (l.p2 - l.p1) / (l.p2 - l.p1).Abs;
            double b = Math.Sqrt(r * r - (pr - c).Norm);
            return new KeyValuePair<Point, Point>(pr + e * b, pr - e * b);
        }
        public KeyValuePair<Point, Point> GetCrossPoints(Circle c2)
        {
            double d = (c - c2.c).Abs;
            double a = Math.Acos((r * r + d * d - c2.r * c2.r) / (2 * r * d));
            double t = (c2.c - c).Arg;
            Point p1 = c + new Point(Math.Cos(t + a) * r, Math.Sin(t + a) * r);
            Point p2 = c + new Point(Math.Cos(t - a) * r, Math.Sin(t - a) * r);
            return new KeyValuePair<Point, Point>(p1, p2);
        }

    }
}