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 Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;



use std::ops::{ Add, Sub , Div , Mul };


#[derive(Debug,Copy,Clone)]
pub struct ComplexNum{
    real :f64,
    imaginary : f64,
}

impl ComplexNum{
    pub fn new (r :f64 , im :f64)-> Self{
        return ComplexNum{real:r , imaginary:im};
    }

    pub fn conjugate(&self)-> Self{
        return ComplexNum::new(self.real , self.imaginary * -1_f64);
    }

    pub fn nearly_equal(&self , other : Self) -> bool{
        let a = 1e-10f64;
        return (self.real - other.real).abs() < a && (self.imaginary - other.imaginary).abs() < a;

    }

    pub fn norm2 (&self ) -> f64{
        return self.real * self.real + self.imaginary * self.imaginary;
    }

    pub fn norm(&self) -> f64{
        return self.norm2().sqrt();
    }
}


impl PartialEq for ComplexNum {
    fn eq(&self, other: &Self) -> bool {
        self.real == other.real && self.imaginary == other.imaginary
    }
}


impl Eq for ComplexNum {}


impl Add for ComplexNum{
    type Output = Self;
    fn add (self , other : Self)-> Self{
        ComplexNum::new(self.real + other.real , self.imaginary + other.imaginary)
    }
}


impl Sub for ComplexNum{
    type Output = Self;
    fn sub (self , other : Self)-> Self{
        ComplexNum::new(self.real - other.real , self.imaginary - other.imaginary)
    }
}


impl Mul for ComplexNum{
    type Output = Self;
    fn mul (self , other : Self)-> Self{
        ComplexNum::new(self.real * other.real - self.imaginary * self.imaginary,
        self.imaginary * other.real - self.real * other.imaginary)
    }
}



pub fn sort_complex_number_with_angle(a : &mut Vec<ComplexNum>) {
    fn orthant (c : &ComplexNum) -> i32{
        if(c.real == 0_f64 && c.imaginary  == 0_f64){
            return 0;
        }
        else if(c.real >= 0_f64 && c.imaginary >= 0_f64){
            return 1;
        }
        else if(c.real <= 0_f64 && c.imaginary >= 0_f64){
            return 2;
        }
        else if(c.real <= 0_f64 && c.imaginary <= 0_f64){
            return 3;
        }
        else {
            return 4;
        }

    }
    
    a.sort_by(| a,b |{
        let a_s = orthant(&a);
        let b_s = orthant(&b);
        if(a_s != b_s){
            return a_s.cmp(&b_s);
        }
        else{
            let ab = a.conjugate() * *b;
            let ba = b.conjugate() * *a;
            return if(ba.imaginary == ab.imaginary){std::cmp::Ordering::Equal}
            else if(ab.imaginary > ba.imaginary){std::cmp::Ordering::Greater}
            else{
                std::cmp::Ordering::Less
            };
        }
    });
}



fn main() {

    input! { 
       n: usize,
       a : [(i64,i64);n],
    }

    
    
    
    let mut b = vec![ComplexNum::new(0_f64,0_f64);n];
    for i in 0..n{
        b[i].real = a[i].0 as f64;
        b[i].imaginary = a[i].1 as f64;
    }

    sort_complex_number_with_angle(&mut b);
    let mut result = vec![];

    for i in 0..n{
        let mut tmp = ComplexNum::new(0_f64,0_f64);
        let mut ans = 0_f64;
        for j in i..n+i{
            tmp = tmp + b[j%n];
            if ans <  tmp.norm2() {
                ans =  tmp.norm2();
            }
            else {
                break;
            }
        }
        result.push(ans);
    }

    result.sort_by(|a,b|{
        if a == b {
            return std::cmp::Ordering::Equal
        }
        else if a < b{
            return std::cmp::Ordering::Less
        }
        else{
           return  std::cmp::Ordering::Greater
        }
    });

    mydbg!(result);
    println!("{:.20}",result[n-1].sqrt());


}