Problem:
Score: 600 points

Problem Statement

E869120 is initially standing at the origin (0, 0) in a two-dimensional plane.

He has N engines, which can be used as follows:

When E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the coordinates (X + x_i, Y + y_i).

E869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.

He wants to go as far as possible from the origin.
Let (X, Y) be his final coordinates. Find the maximum possible value of \sqrt{X^2 + Y^2}, the distance from the origin.

Constraints

1 \leq N \leq 100

-1 \ 000 \ 000 \leq x_i \leq 1 \ 000 \ 000

-1 \ 000 \ 000 \leq y_i \leq 1 \ 000 \ 000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
: :
x_N y_N

Output

Print the maximum possible final distance from the origin, as a real value.
Your output is considered correct when the relative or absolute error from the true answer is at most 10^{-10}.

Sample Input 1

3
0 10
5 -5
-5 -5

Sample Output 1

10.000000000000000000000000000000000000000000000000

The final distance from the origin can be 10 if we use the engines in one of the following three ways:

Use Engine 1 to move to (0, 10).

Use Engine 2 to move to (5, -5), and then use Engine 3 to move to (0, -10).

Use Engine 3 to move to (-5, -5), and then use Engine 2 to move to (0, -10).

The distance cannot be greater than 10, so the maximum possible distance is 10.

Sample Input 2

5
1 1
1 0
0 1
-1 0
0 -1

Sample Output 2

2.828427124746190097603377448419396157139343750753

The maximum possible final distance is 2 \sqrt{2} = 2.82842....
One of the ways to achieve it is:

Use Engine 1 to move to (1, 1), and then use Engine 2 to move to (2, 1), and finally use Engine 3 to move to (2, 2).

Sample Input 3

5
1 1
2 2
3 3
4 4
5 5

Sample Output 3

21.213203435596425732025330863145471178545078130654

If we use all the engines in the order 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5, we will end up at (15, 15), with the distance 15 \sqrt{2} = 21.2132... from the origin.

Sample Input 4

3
0 0
0 1
1 0

Sample Output 4

1.414213562373095048801688724209698078569671875376

There can be useless engines with (x_i, y_i) = (0, 0).

Sample Input 5

1
90447 91000

Sample Output 5

128303.000000000000000000000000000000000000000000000000

Note that there can be only one engine.

Sample Input 6

2
96000 -72000
-72000 54000

Sample Output 6

120000.000000000000000000000000000000000000000000000000

There can be only two engines, too.

Sample Input 7

10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20

Sample Output 7

148.660687473185055226120082139313966514489855137208

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace ProgrammingContestTemplateByDotNetCore
{

    #region "Input and Output Classes"

    class Scanner : IDisposable
    {
        private readonly Queue<string> _buffer;
        private readonly char[] _sep;
        private readonly TextReader _reader;

        public Scanner(TextReader reader = null, char[] sep = null)
        {
            _buffer = new Queue<string>();
            _sep = sep ?? new[] { ' ' };
            _reader = reader ?? Console.In;
        }

        public Scanner(string path, char[] sep = null)
            : this(new StreamReader(path), sep) { }

        private void CheckBuffer()
        {
            if (_buffer.Any() || _reader.Peek() == -1)
                return;

            string str = string.Empty;
            for (;
                string.IsNullOrWhiteSpace(str);
                str = _reader.ReadLine()) { }

            var values = str.Split(_sep).Where(s => !string.IsNullOrWhiteSpace(s));
            foreach (var item in values)
            {
                _buffer.Enqueue(item);
            }
        }

        public string Next()
        {
            CheckBuffer();
            return _buffer.Dequeue();
        }
        public string[] GetStringArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => Next())
                .ToArray();

        public int NextInt() => int.Parse(Next());
        public int[] GetIntArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => NextInt())
                .ToArray();

        public long NextLong() => long.Parse(Next());
        public long[] GetLongArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => NextLong())
                .ToArray();

        public double NextDouble() => double.Parse(Next());
        public double[] GetDoubleArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => NextDouble())
                .ToArray();

        public decimal NextDecimal() => decimal.Parse(Next());
        public decimal[] GetDecimalArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => NextDecimal())
                .ToArray();

        public BigInteger NextBigInt() => BigInteger.Parse(Next());
        public BigInteger[] GetBigIntArray(int count)
            => Enumerable.Range(0, count)
                .Select(e => NextBigInt())
                .ToArray();

        public bool IsEnd
        {
            get
            {
                CheckBuffer();
                return !_buffer.Any();
            }
        }

        public void Dispose()
        {
            if (!_reader.Equals(Console.In))
                _reader.Dispose();
        }
    }

    class Writer : IDisposable
    {
        private readonly TextWriter _writer;
        private readonly StringBuilder _cache;
        private readonly bool _isReactive;

        public Writer(TextWriter writer = null, bool isReactive = false)
        {
            _writer = writer ?? Console.Out;
            _isReactive = isReactive;
            if (!_isReactive)
                _cache = new StringBuilder();
        }

        public Writer(string path)
            : this(new StreamWriter(path)) { }

        public Writer(bool isReactive)
            : this(null, isReactive) { }

        public void Write(object value)
        {
            if (_isReactive)
            {
                _writer.Write(value);
                _writer.Flush();
            }
            else
            {
                _cache.Append(value);
            }
        }

        public void WriteFormat(string format, params object[] values)
        {
            var value = string.Format(format, values);
            Write(value);
        }

        public void WriteLine(object value = null)
        {
            Write($"{value}{Environment.NewLine}");
        }

        public void WriteLine(string format, params object[] values)
        {
            WriteFormat($"{format}{Environment.NewLine}", values);
        }

        public void Dispose()
        {
            if (!_isReactive)
            {
                _writer.Write(_cache);
                _writer.Flush();
            }
            if (!_writer.Equals(Console.Out))
            {
                _writer.Dispose();
            }
        }
    }

#endregion

    class MainClass : IDisposable
    {
#region "Template"

        /// <summary> 入力を受け取る </summary>
        private readonly Scanner sc;
        /// <summary> 出力を行う </summary>
        private readonly Writer wr;
        private const string _inputFile = "input.txt";
        private const string _outFile = "output.txt";

        static void Main(string[] args)
        {
            using (new MainClass()) { }
        }

        public MainClass()
        {
            wr = new Writer(_isReactive);
            // TODO: ファイルに出力したい場合はこっち → wr = new Writer(_outFile);

#if DEBUG
            // 手元では、ファイルから入力を受け取る
            sc = new Scanner(_inputFile);
#else

            // 提出時、標準入力から受け取る
            sc = new Scanner();
#endif

            Solve();
        }

        public void Dispose()
        {
            sc?.Dispose();
            wr?.Dispose();
        }

        #endregion

        int[] dx = { -1, -1, -1, 0, 0, 1, 1, 1 };
        int[] dy = { -1, 0, 1, -1, 1, -1, 0, 1 };
        decimal[] x, y;
        List<Tuple<decimal, decimal>>[] pointsGroup = new List<Tuple<decimal, decimal>>[8];

        void Solve()
        {
            int N = sc.NextInt();
            x = new decimal[N];
            y = new decimal[N];
            for (int i = 0; i < N; i++)
            {
                x[i] = sc.NextDecimal();
                y[i] = sc.NextDecimal();
            }

            decimal ans = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    pointsGroup[j] = new List<Tuple<decimal, decimal>>();
                }

                for (int j = 0; j < N; j++)
                {
                    var xSign = Math.Sign(x[j]);
                    var ySign = Math.Sign(y[j]);
                    for (int k = 0; k < 8; k++)
                    {
                        if (xSign == Math.Sign(dx[k]) && ySign == Math.Sign(dy[k]))
                        {
                            pointsGroup[k].Add(Tuple.Create(x[j], y[j]));
                        }
                    }
                }

                decimal curX = 0, curY = 0;
                foreach (var p in pointsGroup[i])
                {
                    curX += p.Item1;
                    curY += p.Item2;
                }

                int[] priDir = Enumerable.Range(0, 8).Where(e => e != i).ToArray();
                do
                {
                    var tmpX = curX;
                    var tmpY = curY;
                    foreach (var idx in priDir)
                    {
                        foreach (var p in pointsGroup[idx])
                        {
                            var nxtX = tmpX + p.Item1;
                            var nxtY = tmpY + p.Item2;
                            if (tmpX * tmpX + tmpY * tmpY < nxtX * nxtX + nxtY * nxtY)
                            {
                                tmpX = nxtX;
                                tmpY = nxtY;
                            }
                        }
                    }

                    ans = Math.Max(ans, tmpX * tmpX + tmpY * tmpY);
                }
                while (NextPermutation(priDir));
            }

            wr.WriteLine($"{Sqrt(ans):F30}");
        }

        decimal Sqrt(decimal value)
        {
            var low = decimal.Zero;
            var high = value;
            for (int i = 0; i < 1000; i++)
            {
                var mid = (low + high) / 2;
                if (mid * mid <= value)
                {
                    low = mid;
                }
                else
                {
                    high = mid;
                }
            }
            return low;
        }

        /// <summary>
        /// TODO: リアクティブ問題か否かを指定してね♪
        /// </summary>
        private const bool _isReactive = false;

        bool NextPermutation<T>(T[] ar) where T : IComparable<T>
        {
            int left = ar.Length - 1;
            Func<int, int, int> CompForCalcNextPermutation = (int i, int j) => ar[i].CompareTo(ar[j]);
            while (0 < left && CompForCalcNextPermutation(left - 1, left) >= 0)
            {
                left--;
            }
            if (left == 0)
            {
                return false;
            }
            int right = ar.Length - 1;
            while (CompForCalcNextPermutation(right, left - 1) <= 0)
            {
                right--;
            }
            T tmp = ar[left - 1];
            ar[left - 1] = ar[right];
            ar[right] = tmp;
            Array.Reverse(ar, left, ar.Length - left);
            return true;
        }
    }

    class Timer
    {
        private DateTime _start;
        private readonly TimeSpan? _limit;

        public Timer() { Reset(); }

        public Timer(TimeSpan limit)
            : this() { _limit = limit; }

        public void Reset() { _start = DateTime.Now; }

        public TimeSpan Elapse => DateTime.Now - _start;

        public TimeSpan Remaining
        {
            get
            {
                if (!_limit.HasValue)
                    throw new InvalidOperationException("Not set limit value");
                return _limit.Value - Elapse;
            }
        }
    }

    class XorShift
    {
        private uint x = 123456789;
        private uint y = 362436069;
        private uint z = 521288629;
        private uint w;

        public XorShift(uint seed = 88675123)
        {
            w = seed;
        }

        public uint Next(bool heavyOk = false)
        {
            if (heavyOk) RandomLoop();
            var t = x ^ (x << 11);
            x = y;
            y = z;
            z = w;
            return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        }

        public ulong Next64(bool heavyOk = false)
        {
            if (heavyOk) RandomLoop();
            ulong tmp = Next();
            return (tmp << 32) | tmp;
        }

        private void RandomLoop()
        {
            var loopNum = Next() % 100;
            while (loopNum-- > 0) Next();
        }
    }
}