Problem:
Simultaneous Equation

Write a program which solve a simultaneous equation:

ax + by = c

dx + ey = f

The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.

Input

The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF.

Output

For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places.

Sample Input 1

1 2 3 4 5 6
2 -1 -2 -1 -1 -5

Output for the Sample Input 1

-1.000 2.000
1.000 4.000

Sample Input 2

2 -1 -3 1 -1 -3
2 -1 -3 -9 9 27

Output for the Sample Input 2

0.000 3.000
0.000 3.000

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections;
using System.Linq;

namespace Simultaneous_Equation
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList[] result = new ArrayList[2];
            result[0] = new ArrayList();
            result[1] = new ArrayList();

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input)) break;

                var strcoe = input.Split(' ');
                if (strcoe.Length != 6) continue;

                double[] coe = new double[6];
                for(var i = 0; i < coe.Length; i++)
                {
                    coe[i] = double.Parse((strcoe[i]));
                }

                ArrayList[] matrix1 = new ArrayList[2];
                for(int i = 0; i < 2; i++)
                {
                    matrix1[i] = new ArrayList();
                    for (int j = 0; j < 2; j++)
                    {
                        matrix1[i].Add(coe[i * 3 + j]);
                    }
                }

                ArrayList[] matrix2 = new ArrayList[2];
                for (int i = 0; i < 2; i++)
                {
                    matrix2[i] = new ArrayList();
                    matrix2[i].Add(coe[i * 3 + 2]);
                }

                Matrix mt = new Matrix();
                ArrayList[] inv = mt.Inverse_2_2(matrix1);
                if(inv == null) { continue; }

                ArrayList[] xy = mt.Product(inv, matrix2);
                result[0].Add(xy[0][0]);
                result[1].Add(xy[1][0]);
            }

            for(int i = 0; i < result[0].Count; i++)
            {
                Console.WriteLine("{0:f3} {1:f3}", result[0][i], result[1][i]);
            }
        }
    }

    class Matrix
    {
        public ArrayList[] Inverse_2_2(ArrayList[] matrix)
        {
            ArrayList[] inv = new ArrayList[2];
            for (int i = 0; i < 2; i++)
            {
                inv[i] = new ArrayList();
                for (int j = 0; j < 2; j++)
                {
                    inv[i].Add(.0);
                }
            }
            
            var det = (double)matrix[0][0] * (double)matrix[1][1] - (double)matrix[0][1] * (double)matrix[1][0];
            if(det == 0) { return null; }

            inv[0][0] = (double)matrix[1][1] / (double)det;
            inv[1][1] = (double)matrix[0][0] / (double)det;
            inv[0][1] = (double)matrix[0][1] / (double)-det;
            inv[1][0] = (double)matrix[1][0] / (double)-det;

            return inv;
        }

        public ArrayList[] Product(ArrayList[] matrix1, ArrayList[] matrix2)
        {
            var row1 = matrix1.Count();
            var col1 = matrix1[0].Count;
            var col2 = matrix2[0].Count;

            ArrayList[] result = new ArrayList[2];
            for (int i = 0; i < row1; i++)
            {
                result[i] = new ArrayList();
                for (int j = 0; j < col2; j++)
                {
                    result[i].Add(.0);
                }
            }

            for(int i = 0; i < row1; i++)
            {
                for(int j = 0; j < col2; j++)
                {
                    double val = 0;
                    for(int k = 0; k < col1; k++) {
                        val += (double)matrix1[i][k] * (double)matrix2[k][j];
                    }
                    result[i][j] = val;
                }
            }
            
            return result;
        }
    }
}