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: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using static Exg;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var pa=new Pair[n];
		for(int i = 0;i<n;i++) {
			pa[i]=new Pair(sc.Da);
		}
		var g=new Pair(0,0);
		double ans=0;
		var ca=Psort2(pa,new Pair(0,0));
		for(int i = 0;i<n;i++) {
			var c=new Pair(0,0);
			for(int j = i;j<n+i;j++) {
				c+=ca[j].Item1;
				ans=Max(ans,Gp0(g,c));
			}
		}
		Console.WriteLine(ans);
	}
}
public struct Pair{
	public double x,y;
	public Pair(double x,double y){this.x=x;this.y=y;}
	public Pair(double[] da){x=da[0];y=da[1];}
	public Pair(Pair p){x=p.x;y=p.y;}
	public override string ToString()=>x.ToString()+" "+y.ToString();
	public static Pair operator+(Pair a,Pair b){a.x+=b.x;a.y+=b.y;return a;}
	public static Pair operator-(Pair a,Pair b){a.x-=b.x;a.y-=b.y;return a;}
	public static Pair operator*(Pair a,double n){a.x*=n;a.y*=n;return a;}
	public static Pair operator/(Pair a,double n){a.x/=n;a.y/=n;return a;}
}
static class Exg{
	static public double Gp0(Pair a,Pair b){return Sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
	static public Tuple<bool,Pair> Gp1(Pair p1,Pair p2,Pair p3,Pair p4){
		double t1=(p4.y-p3.y)*(p4.x-p1.x)-(p4.x-p3.x)*(p4.y-p1.y);
		double t2=(p2.x-p1.x)*(p4.y-p1.y)-(p2.y-p1.y)*(p4.x-p1.x);
		double t3=(p2.x-p1.x)*(p4.y-p3.y)-(p2.y-p1.y)*(p4.x-p3.x);
		if(t3==0){
			if(Abs(Atan2(p2.y-p1.y,p2.x-p1.x))!=Abs(Atan2(p3.y-p1.y,p3.x-p1.x))){return Tuple.Create(p1.x==p3.x&&p1.y==p3.y?true:false,p1);}
			var a=new Tuple<Pair,int>[]{Tuple.Create(p1,1),Tuple.Create(p2,2),Tuple.Create(p3,3),Tuple.Create(p4,4)};
			Array.Sort(a,(d,e)=>{var c=d.Item1.x.CompareTo(e.Item1.y);return c==0?e.Item1.y.CompareTo(d.Item1.y):c;});
			return Tuple.Create((Abs(a[0].Item2-a[1].Item2)!=1||Abs(a[2].Item2-a[3].Item2)!=1)||(a[1].Item1.x==a[2].Item1.x&&a[1].Item1.y==a[2].Item1.y)?true:false,a[1].Item1);
		}
		double t4=t1/t3,t5=t2/t3;
		if(t4<0||t4>1||t5<0||t5>1){return Tuple.Create(false,new Pair(0,0));}
		else{return Tuple.Create(true,new Pair(p1.x+t4*(p2.x-p1.x),p1.y+t4*(p2.y-p1.y)));}
	}
	static public double Gp2(Pair p1,Pair p2,Pair p0){return Abs((p2.y-p1.y)*p0.x-(p2.x-p1.x)*p0.y+p2.x*p1.y-p1.x*p2.y)/Sqrt((p2.y-p1.y)*(p2.y-p1.y)+(p2.x-p1.x)*(p2.x-p1.x));}
	static public double Gp3(Pair p1,Pair p2,Pair p0){return (p1.x-p2.x)*(p0.y-p1.y)+(p1.y-p2.y)*(p1.x-p0.x);}
	static public double Gp4(Pair a,Pair b,Pair c){
		double a1=a.x-b.x,a2=a.y-b.y,c1=c.x-b.x,c2=c.y-b.y;
		return Acos((a1*c1+a2*c2)/Sqrt((a1*a1+a2*a2)*(c1*c1+c2*c2)))*180/PI;
	}
	static public Tuple<bool,Pair> Gp5(Pair p1,Pair p2,Pair p0){
		double rx=p0.x,ry=p0.y;
		if(p1.x==p2.x){rx=p1.x;}
		else if(p1.y==p2.y){ry=p1.y;}
		else{
			double m1=(p2.y-p1.y)/(p2.x-p1.x),b1=p1.y-(m1*p1.x),m2=-1.0/m1,b2=p0.y-(m2*p0.x);
			rx=(b2-b1)/(m1-m2);
			ry=(b2*m1-b1*m2)/(m1-m2);
		}
		return Tuple.Create(((p1.x>=rx&&p2.x<=rx)||(p2.x>=rx&&p1.x<=rx))&&((p1.y>=ry&&p2.y<=ry)||(p2.y>=ry&&p1.y<=ry)),new Pair(rx,ry));
	}
	static public Pair Gp6(Pair a,Pair b,Pair c,int n){
		double l1=Sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
		double l2=Sqrt((c.x-b.x)*(c.x-b.x)+(c.y-b.y)*(c.y-b.y));
		double ex=(a.x+(b.x+(c.x-b.x)*(l1/l2)))/2,ey=(a.y+(b.y+(c.y-b.y)*(l1/l2)))/2;
		ex+=(ex-b.x)*n;ey+=(ey-b.y)*n;
		return new Pair(ex,ey);
	}
	static public Pair Gp7(Pair a,double k,double p){return new Pair(a.x+k*Cos(p),a.y+k*Sin(p));}
	static public bool Gp8(Pair a,Pair b,Pair c){return (c.x-a.x)*(b.y-a.y)==(b.x-a.x)*(c.y-a.y);}
	static public Tuple<Pair,double>[] Psort(Pair[] pa,Pair p){
		var arr=new Tuple<Pair,double>[pa.Length];
		for(int i = 0;i<pa.Length;i++) {arr[i]=Tuple.Create(pa[i],Atan2(pa[i].y-p.y,pa[i].x-p.x)*180/PI+180);}
		Array.Sort(arr,(u,v)=>u.Item2.CompareTo(v.Item2));
		return arr;
	}
	static public Tuple<Pair,double>[] Psort2(Pair[] pa,Pair p){
		int n=pa.Length;
		var arr=new Tuple<Pair,double>[n<<1];
		for(int i = 0;i<n;i++) {
			arr[i]=Tuple.Create(pa[i],Atan2(pa[i].y-p.y,pa[i].x-p.x)*180/PI+180);
			arr[i+n]=Tuple.Create(pa[i],Atan2(pa[i].y-p.y,pa[i].x-p.x)*180/PI+540);
		}
		Array.Sort(arr,(u,v)=>u.Item2.CompareTo(v.Item2));
		return arr;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}