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.Linq;
using System.Text;

namespace CGL_7_E_CrossPointsofCircles
{
	class Program
	{
		static void Main ( string[] args )
		{
			int[] inputNum1 = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);
			int[] inputNum2 = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);

			Circle circle1 = new Circle (inputNum1[0], inputNum1[1], inputNum1[2]);
			Circle circle2 = new Circle (inputNum2[0], inputNum2[1], inputNum2[2]);

			Vector2[] result = Circle.CrossPoint (circle1, circle2).OrderBy (item => item.X).ThenBy (item => item.Y).ToArray ();

			Console.WriteLine (result[0].X + " " + result[0].Y + " " + result[1].X + " " + result[1].Y);
		}
	}

	class Vector2
	{
		public Vector2 ( decimal x, decimal y )
		{
			this.X = x;
			this.Y = y;
		}

		public decimal X { private set; get; }
		public decimal Y { private set; get; }

		public static Vector2 operator + ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X + ob2.X, ob1.Y + ob2.Y);
		}
		public static Vector2 operator - ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X - ob2.X, ob1.Y - ob2.Y);
		}
		public static Vector2 operator * ( Vector2 ob, decimal scalar )
		{
			return new Vector2 (ob.X * scalar, ob.Y * scalar);
		}

		private static decimal Sqrt ( decimal number )
		{
			return new decimal (Math.Sqrt (decimal.ToDouble (number)));
		}
		public decimal Length ()
		{
			return X * X + Y * Y;
		}
		public decimal Normalize ()
		{
			Vector2 tmp = new Vector2 (X, Y);
			return Sqrt (tmp.Length ());
		}
	}

	class Circle
	{
		public Circle ( decimal x, decimal y, decimal radius )
		{
			this.Point = new Vector2 (x, y);
			this.Radius = radius;
		}

		public Vector2 Point { private set; get; }
		public decimal Radius { private set; get; }

		public static Vector2[] CrossPoint ( Circle circle1, Circle circle2 )
		{
			decimal distance = (circle2.Point - circle1.Point).Normalize ();

			decimal tmp = (circle1.Radius * circle1.Radius + distance * distance - circle2.Radius * circle2.Radius) /
				(2 * circle1.Radius * distance);

			decimal radian = new decimal (Math.Acos (decimal.ToDouble (tmp)));

			Vector2 difference = circle2.Point - circle1.Point;
			decimal radian2 = new decimal (Math.Atan2 (decimal.ToDouble (difference.Y), decimal.ToDouble (difference.X)));

			return new Vector2[] { 
				circle1.Point + Polar (circle1.Radius, radian2 + radian),
				circle1.Point + Polar (circle1.Radius, radian2 - radian) 
			};
		}

		public static Vector2 Polar ( decimal radian, decimal radian2 )
		{
			double l = decimal.ToDouble (radian);
			double r = decimal.ToDouble (radian2);

			return new Vector2 (new decimal (Math.Cos (r) * l), new decimal (Math.Sin (r) * l));
		}
	}
}