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 (Python):
n=int(input())
xy=[tuple(map(int,input().split())) for _ in range(n)]
import numpy as np
e=(1,0)
xyz=[]
k=0
for x,y in xy:
  if x==0 and y==0:continue
  k+=1
  l=np.linalg.norm((x,y))
  z=np.inner((x/l,y/l),e)
  theta = np.rad2deg(np.arccos(z))
  if y<0:
    theta=360-theta
  xyz.append((x,y,theta))
xyz.sort(key=lambda x:x[2])


tx,ty=0,0
c=[(0,0)]
for x,y,z in xyz:
  tx+=x
  ty+=y
  c.append((tx,ty))
for x,y,z in xyz:
  tx+=x
  ty+=y
  c.append((tx,ty))

ans=0
for i in range(k):
  for j in range(k):
    x=c[i+j+1][0]-c[i][0]
    y=c[i+j+1][1]-c[i][1]
    ans=max(ans,(x**2+y**2)**0.5)
print(ans)

Solution (Python):
import sys
import math

input = sys.stdin.readline
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
txy = sorted([(math.atan2(y, x), x, y) for x, y in xy])
txy += txy
i = 0
ans = 0
for i in range(N):
    for j in range(i, 2 * N):
        if j - i > N:
            continue
        xs = sum(map(lambda x: x[1], txy[i:j]))
        ys = sum(map(lambda x: x[2], txy[i:j]))
        ans = max(ans, math.sqrt(xs*xs+ys*ys))
print(ans)

Solution (Python):
from math import atan2, sqrt

def main():
    n = int(input())
    engines = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        rad = atan2(engines[i][1], engines[i][0])
        engines[i].append(rad)
    engines.sort(key=lambda x: x[2])
    ans = 0
    for k in range(1, n+1):
        for i in range(n):
            x_sum, y_sum = 0, 0
            for j in range(i, i+k):
                p = j%n
                x_sum += engines[p][0]
                y_sum += engines[p][1]
            tmp = x_sum**2 + y_sum**2
            if ans < tmp:
                ans = tmp
    print(sqrt(ans))

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from math import atan2, sqrt

N = int(input())
A = [t for _ in range(N) if (t := tuple(map(int, input().split()))) != (0, 0)]

A.sort(key=lambda x: atan2(x[1], x[0]))


Ax, Ay = [], []
for _, v in itertools.groupby(A, key=lambda x: atan2(x[1], x[0])):
    sx, sy = 0, 0
    for vx, vy in v:
        sx += vx
        sy += vy
    Ax.append(sx)
    Ay.append(sy)

Nu = len(Ax)

Ax = [0] + list(itertools.accumulate(Ax * 2))
Ay = [0] + list(itertools.accumulate(Ay * 2))

ans = 0
for i in range(Nu + 1):
    for j in range(i + 1, min(i + Nu + 1, 2 * Nu + 1)):
        ans = max(ans, (Ax[j] - Ax[i]) ** 2 + (Ay[j] - Ay[i]) ** 2)

print(sqrt(ans))

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
def sub(x,y):
    xx = 0
    yy = 0
    for tx,ty in xy:
        if x*tx+y*ty>0:
            xx += tx
            yy += ty
    return (xx*xx+yy*yy)**0.5
ans = -1
for i,(x,y) in enumerate(xy):
    for x2,y2 in xy:
        ans = max(ans, sub((x+x2)/2,(y+y2)/2))
print(ans)

Solution (Python):
def solve():
    from math import atan2, degrees, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = degrees(atan2(b, a))
        sx += a
        sy += b
        txy.append([theta_0, a, b])
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()

Solution (Python):
def solve():
    from math import atan2, degrees, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = degrees(atan2(b, a))
        sx += a
        sy += b
        txy.append((theta_0, a, b))
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()

Solution (Python):
def solve():
    from math import atan2, pi, hypot
    n = int(input())
    txy = []
    sx, sy = 0, 0
    for i in range(n):
        a, b = map(int, input().split())
        theta_0 = atan2(b, a)
        sx += a
        sy += b
        txy.append((theta_0, a, b))
    txy.sort()
    ans = hypot(sx, sy)
    for i in range(n):
        for j in range(i + 1, n):
            tx, ty = 0, 0
            for k in range(i, j):
                theta, x, y = txy[k]
                tx += x
                ty += y
                ans = max(ans, hypot(tx, ty))
                ans = max(ans, hypot(sx - tx, sy - ty))
    print(ans)

solve()

Solution (Python):
import sys
import numpy as np
import math
def input(): return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    engine = np.zeros((n, 3))
    for i in range(n):
        engine[i][0], engine[i][1] = map(int, input().split())
        engine[i][2] = math.atan2(engine[i][1], engine[i][0])
    engines = engine[np.argsort(engine[:, 2])]
    sumen = sum(engines)
    ans = sumen[0]**2+sumen[1]**2
    for i in range(n):
        for j in range(i, n):
            sump=sum(engines[i:j+1])
            ans=max(ans,sump[0]**2+sump[1]**2,(sump[0]-sumen[0])**2+(sump[1]-sumen[1])**2)
    print(math.sqrt(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())
vec = []

xs, ys = 0, 0
for _ in range(n):
    x, y = map(int, input().split())
    t = math.atan2(y, x)
    if t < 0:
        t += 2 * math.pi
    xs += x
    ys += y
    vec.append((t, x, y))
vec.sort()

max_val = xs * xs + ys * ys
for l in range(n):
    for m in range(1, n):
        val = 0
        x, y = 0, 0
        for i in range(l, l + m):
            _, xi, yi = vec[i % n]
            x += xi
            y += yi
        max_val = max(max_val, x * x + y * y)
print(math.sqrt(max_val))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N = I()
xy = [tuple(MI()) for i in range(N)]

from math import gcd,sqrt

ans = 0
for i in range(N):  
    x,y = xy[i]
    X1,Y1 = 0,0
    X2,Y2 = 0,0
    X3,Y3 = 0,0
    X4,Y4 = 0,0
    if x == 0 and y == 0:
        continue
    else:
        for j in range(N):
            a,b = xy[j]
            if a == 0 and b == 0:
                continue
            elif x//gcd(x,y) == a//gcd(a,b) and y//gcd(x,y) == b//gcd(a,b):
                X1 += a
                Y1 += b
                X2 += a
                Y2 += b
            elif (-y)*a + x*b > 0:
                X1 += a
                Y1 += b
                X3 += a
                Y3 += b
            elif y*a + (-x)*b > 0:
                X2 += a
                Y2 += b
                X4 += a
                Y4 += b
        ans = max(ans,X1**2+Y1**2,X2**2+Y2**2,X3**2+Y3**2,X4**2+Y4**2)

print(sqrt(ans))

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    import cmath
    import itertools
    import math
    import sys


    sys.setrecursionlimit(10 ** 9)
    IINF = 10 ** 18
    MOD = 10 ** 9 + 7
    


    INF = float("inf")
    PI = cmath.pi
    TAU = cmath.pi * 2
    EPS = 1e-10


    class Point:
        """
        2次元空間上の点
        """

        
        CCW_COUNTER_CLOCKWISE = 1
        
        CCW_CLOCKWISE = -1
        
        CCW_ONLINE_BACK = 2
        
        CCW_ONLINE_FRONT = -2
        
        CCW_ON_SEGMENT = 0

        def __init__(self, x: float, y: float):
            self.c = complex(x, y)
            
        @property
        def x(self):
            return self.c.real

        @property
        def y(self):
            return self.c.imag

        @staticmethod
        def from_complex(c: complex):
            return Point(c.real, c.imag)

        @staticmethod
        def from_polar(r: float, phi: float):
            c = cmath.rect(r, phi)
            return Point(c.real, c.imag)

        def __add__(self, p):
            """
            :param Point p:
            """
            c = self.c + p.c
            return Point(c.real, c.imag)

        def __iadd__(self, p):
            """
            :param Point p:
            """
            self.c += p.c
            return self

        def __sub__(self, p):
            """
            :param Point p:
            """
            c = self.c - p.c
            return Point(c.real, c.imag)

        def __isub__(self, p):
            """
            :param Point p:
            """
            self.c -= p.c
            return self

        def __mul__(self, f: float):
            c = self.c * f
            return Point(c.real, c.imag)

        def __imul__(self, f: float):
            self.c *= f
            return self

        def __truediv__(self, f: float):
            c = self.c / f
            return Point(c.real, c.imag)

        def __itruediv__(self, f: float):
            self.c /= f
            return self

        def __repr__(self):
            return "({}, {})".format(round(self.x, 10), round(self.y, 10))

        def __neg__(self):
            c = -self.c
            return Point(c.real, c.imag)

        def __eq__(self, p):
            return abs(self.c - p.c) < EPS

        def __abs__(self):
            return abs(self.c)

        @staticmethod
        def ccw(a, b, c):
            """
            線分 ab に対する c の位置
            線分上にあるか判定するだけなら on_segment とかのが速い
            :param Point a:
            :param Point b:
            :param Point c:
            """
            b = b - a
            c = c - a
            det = b.det(c)
            if det > EPS:
                return Point.CCW_COUNTER_CLOCKWISE
            if det < -EPS:
                return Point.CCW_CLOCKWISE
            if b.dot(c) < -EPS:
                return Point.CCW_ONLINE_BACK
            if c.norm() - b.norm() > EPS:
                return Point.CCW_ONLINE_FRONT
            return Point.CCW_ON_SEGMENT

        def dot(self, p):
            """
            内積
            :param Point p:
            :rtype: float
            """
            return self.x * p.x + self.y * p.y

        def det(self, p):
            """
            外積
            :param Point p:
            :rtype: float
            """
            return self.x * p.y - self.y * p.x

        def dist(self, p):
            """
            距離
            :param Point p:
            :rtype: float
            """
            return abs(self.c - p.c)

        def norm(self):
            """
            原点からの距離
            :rtype: float
            """
            return abs(self.c)

        def phase(self):
            """
            原点からの角度
            :rtype: float
            """
            return cmath.phase(self.c)

        def angle(self, p, q):
            """
            p に向いてる状態から q まで反時計回りに回転するときの角度
            -pi <= ret <= pi
            :param Point p:
            :param Point q:
            :rtype: float
            """
            return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c) + PI) % TAU - PI

        def area(self, p, q):
            """
            p, q となす三角形の面積
            :param Point p:
            :param Point q:
            :rtype: float
            """
            return abs((p - self).det(q - self) / 2)

        def projection_point(self, p, q, allow_outer=False):
            """
            線分 pq を通る直線上に垂線をおろしたときの足の座標
            :param Point p:
            :param Point q:
            :param allow_outer: 答えが線分の間になくても OK
            :rtype: Point|None
            """
            diff_q = q - p
            
            r = (self - p).dot(diff_q) / abs(diff_q)
            
            phase = diff_q.phase()

            ret = Point.from_polar(r, phase) + p
            if allow_outer or (p - ret).dot(q - ret) < EPS:
                return ret
            return None

        def reflection_point(self, p, q):
            """
            直線 pq を挟んで反対にある点
            :param Point p:
            :param Point q:
            :rtype: Point
            """
            
            r = abs(self - p)
            
            angle = p.angle(q, self)
            
            angle = (q - p).phase() - angle
            return Point.from_polar(r, angle) + p

        def on_segment(self, p, q, allow_side=True):
            """
            点が線分 pq の上に乗っているか
            :param Point p:
            :param Point q:
            :param allow_side: 端っこでギリギリ触れているのを許容するか
            :rtype: bool
            """
            if not allow_side and (self == p or self == q):
                return False
            
            
            return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS
        
    N=I()
    P=[]
    ans=0
    for _ in range(N):
        x,y=MI()
        P.append(Point(x,y))
            
    """
    進みたい角度を決める．
    単位円をM等分して，その単位ベクトルとの内積が正なら採用，をM回
    """
    M=5*10**5
    dt=2*PI/M
    ans=0
    
    for i in range(M+1):
        tempx=0
        tempy=0
        p=Point.from_polar(1,i*dt)
        for j in range(N):
            if P[j].dot(p)>0:
                tempx+=P[j].x
                tempy+=P[j].y
                
        d=(tempx**2 + tempy**2)**0.5
        if d>ans:
            ans=d
            
    print(ans)
             

main()

Solution (Python):
import math

n = int(input())
XY = [list(map(int,input().split())) for i in range(n)]

XY.sort(key=lambda x: math.atan2(x[1],x[0]))
XY += XY

ans = 0
for i in range(n):
    x = 0
    y = 0
    for j in range(n):
        nx,ny = XY[i+j]
        x += nx
        y += ny
        ans = max(ans,(x**2+y**2)**0.5)
print(ans)

Solution (Python):
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x: math.atan2(x[1],x[0]))
l += l
ans = 0
for i in range(n):
    x = y = 0
    for j in range(n):
        nx,ny = l[i+j]
        x += nx
        y += ny
        ans = max(ans,(x**2+y**2)**0.5)
print(ans)

Solution (Python):
import math


def calc_angle(X, Y):
    assert X != 0 or Y != 0
    TREND_INF = 10**6 + 1
    if X == 0:
        angle = math.atan(TREND_INF)
        if Y < 0:
            angle += math.pi
    else:
        angle = math.atan(Y / X)
        if X < 0:
            angle += math.pi
    return angle  


def main():
    N = int(input())
    engines = list()
    for _ in range(N):
        X, Y = list(map(int, input().split(' ')))
        if X == Y == 0:
            continue
        angle = calc_angle(X, Y)
        engines.append((angle, X, Y))
    N = len(engines)
    if N == 0:
        print(0)
        return
    engines.sort()  
    
    dist = [[0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            k = i
            sx = engines[k][1]
            sy = engines[k][2]
            while k != j:
                k = (k + 1) % N
                sx += engines[k][1]
                sy += engines[k][2]
            dist[i][j] = math.sqrt(sx**2 + sy**2)
    ans = 0
    for i in range(N):
        for j in range(N):
            ans = max(ans, dist[i][j])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import cmath
import math
N = int(input())
Engines = []
ans = 0

sumx, sumy = 0, 0
for _ in range(N):
    x, y = map(int, input().split())
    z = complex(x, y)
    arg_deg = cmath.phase(z)
    sumx += x
    sumy += y
    Engines.append((arg_deg, x, y))
ans = max(ans, math.hypot(sumx, sumy))
Engines.sort()
for i in range(N):
    for j in range(i, N):
        sub_x = 0
        sub_y = 0
        for k in range(i, j+1):
            deg, dx, dy = Engines[k]
            sub_x += dx
            sub_y += dy
        ans = max(ans, math.hypot(sub_x, sub_y))
        ans = max(ans, math.hypot(sumx-sub_x, sumy-sub_y))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

class Vec:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)

    def __add__(self, other):
        return Vec(self.x+other.x, self.y+other.y)

    def __sub__(self, other):
        return Vec(self.x-other.x, self.y-other.y)

    def __mul__(self, k):
        return Vec(self.x*k, self.y*k)

    def __truediv__(self, k):
        return Vec(self.x/k, self.y/k)

    def abs(self):
        return (self.x**2 + self.y**2)**.5

    def dot(self, other):
        return self.x*other.x + self.y*other.y

    def cross(self, other):
        return self.x*other.y - self.y*other.x

    def rot(self, ang):
        c = math.cos(ang)
        s = math.sin(ang)
        return Vec(c*self.x-s*self.y, s*self.x+c*self.y)

def convex_hull(points, eps=1e-12):
    n = len(points)
    points.sort(key=lambda p: (p.x, p.y))
    k = 0  
    ch = [None] * (2*n)
    
    for i in range(n):
        while k > 1 and (ch[k-1]-ch[k-2]).cross(points[i]-ch[k-1]) < eps:
            k -= 1
        ch[k] = points[i]
        k += 1
    t = k
    
    for i in range(0, n-1)[::-1]:
        while k > t and (ch[k-1]-ch[k-2]).cross(points[i]-ch[k-1]) < eps:
            k -= 1
        ch[k] = points[i]
        k += 1
    return ch[:k-1]

N = int(input())
xy = [Vec(*tuple(map(int, input().split()))) for _ in range(N)]
points = [Vec(0, 0)]
for v in xy:
    npoints = points[:]
    for u in points:
        npoints.append(u + v)
    points = convex_hull(npoints)
ans = max(v.abs() for v in points)
print(ans)

Solution (Python):
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    txy = []
    for x, y in XY:
        t = math.atan2(y, x)
        txy.append([t, x, y])

    txy.sort()

    ans = 0
    for i in range(N):
        tmpx = 0
        tmpy = 0
        for j in range(N):
            tmpx += txy[(i + j) % N][1]
            tmpy += txy[(i + j) % N][2]
            ans = max(ans, math.sqrt(tmpx ** 2 + tmpy ** 2))


    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    txy = []
    for x, y in XY:
        t = math.atan2(x, y)
        txy.append([t, x, y])

    txy.sort()

    ans = 0
    for i in range(N):
        tmpx = 0
        tmpy = 0
        for j in range(N):
            tmpx += txy[(i + j) % N][1]
            tmpy += txy[(i + j) % N][2]
            ans = max(ans, math.sqrt(tmpx ** 2 + tmpy ** 2))


    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    ans = 0

    for i, (x, y) in enumerate(XY):
        if x == 0:
            katamuki =  1 / (10 ** 7)
            katamuki2 =  - 1 / (10 ** 7)
        else:
            katamuki = y / x + 1 / (10 ** 7)
            katamuki2 = y / x - 1 / (10 ** 7)
        plus = [0, 0]
        minus = [0, 0]
        plus2 = [0, 0]
        minus2 = [0, 0]
        for j, (xx, yy) in enumerate(XY):
            if yy > katamuki * xx:
                plus[0] += xx
                plus[1] += yy
            else:
                minus[0] += xx
                minus[1] += yy

            if yy > katamuki2 * xx:
                plus2[0] += xx
                plus2[1] += yy
            else:
                minus2[0] += xx
                minus2[1] += yy

        ans = max(ans, math.sqrt(plus[0] ** 2 + plus[1] ** 2))
        ans = max(ans, math.sqrt(minus[0] ** 2 + minus[1] ** 2))
        ans = max(ans, math.sqrt(plus2[0] ** 2 + plus2[1] ** 2))
        ans = max(ans, math.sqrt(minus2[0] ** 2 + minus2[1] ** 2))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    ans = 0

    
    
    tmp = [0, 0]
    for x, y in XY:
        if x > 0:
            tmp[0] += x
            tmp[1] += y
        elif x == 0 and y > 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if x > 0:
            tmp[0] += x
            tmp[1] += y
        elif x == 0 and y < 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if x < 0:
            tmp[0] += x
            tmp[1] += y
        elif x == 0 and y > 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if x < 0:
            tmp[0] += x
            tmp[1] += y
        elif x == 0 and y < 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if y > 0:
            tmp[0] += x
            tmp[1] += y
        elif y == 0 and x > 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if y < 0:
            tmp[0] += x
            tmp[1] += y
        elif y == 0 and x > 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if y > 0:
            tmp[0] += x
            tmp[1] += y
        elif y == 0 and x < 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    
    
    tmp = [0, 0]
    for x, y in XY:
        if y < 0:
            tmp[0] += x
            tmp[1] += y
        elif y == 0 and x < 0:
            tmp[0] += x
            tmp[1] += y

    ans = max(ans, math.sqrt(tmp[0] ** 2 + tmp[1] ** 2))

    for i, (x, y) in enumerate(XY):
        if x == 0:
            katamuki = 0
            katamuki2 = float("inf")
        else:
            katamuki = y / x
            if y == 0:
                katamuki2 = float("inf")
            else:
                katamuki2 = -(x / y)
        plus = [0, 0]
        minus = [0, 0]
        plus2 = [0, 0]
        minus2 = [0, 0]
        for j, (xx, yy) in enumerate(XY):
            if i == j:
                continue
            if yy > katamuki * xx:
                plus[0] += xx
                plus[1] += yy
            else:
                minus[0] += xx
                minus[1] += yy

            if katamuki2 == float("inf"):
                if xx > 0:
                    plus2[0] += xx
                    plus2[1] += yy
                else:
                    minus2[0] += xx
                    minus2[1] += yy
            else:
                if yy > katamuki2 * xx:
                    plus2[0] += xx
                    plus2[1] += yy
                else:
                    minus2[0] += xx
                    minus2[1] += yy

        ans = max(ans, math.sqrt(plus[0] ** 2 + plus[1] ** 2))
        ans = max(ans, math.sqrt(minus[0] ** 2 + minus[1] ** 2))
        ans = max(ans, math.sqrt(plus2[0] ** 2 + plus2[1] ** 2))
        ans = max(ans, math.sqrt(minus2[0] ** 2 + minus2[1] ** 2))
        ans = max(ans, math.sqrt((plus[0] + x) ** 2 + (plus[1] + y) ** 2))
        ans = max(ans, math.sqrt((minus[0] + x) ** 2 + (minus[1] + y) ** 2))
        ans = max(ans, math.sqrt((plus2[0] + x) ** 2 + (plus2[1] + y) ** 2))
        ans = max(ans, math.sqrt((minus2[0] + x) ** 2 + (minus2[1] + y) ** 2))

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


import math


def arg(x, y):
    c = x / math.sqrt(x * x + y * y)
    t = math.acos(c)

    if y < 0:
        t = 2 * math.pi - t

    return t


def dist2(x, y):
    return x * x + y * y


def main():
    N = gete(int)
    E = []
    for _ in range(N):
        x, y = geta(int)
        if x != 0 or y != 0:
            E.append((arg(x, y), x, y))

    E.sort()
    N = len(E)

    ans2 = 0
    for i in range(N):
        j = i
        px, py = (0, 0)
        _, qx, qy = E[i]
        c = 0
        while c < N and dist2(px, py) <= dist2(qx, qy):
            j += 1
            c += 1
            px, py = qx, qy
            _, ex, ey = E[j % N]
            qx, qy = px + ex, py + ey

        tmp = dist2(px, py)

        if ans2 < tmp:
            ans2 = tmp

    print(math.sqrt(ans2))

    ans = 0


if __name__ == "__main__":
    main()

Solution (Python):
import cmath
from math import pi

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    if (x,y)!=(0,0):
        z=complex(x,y)
        arg=cmath.phase(z)
        p.append((arg,z))

EPS=10**-6
N=len(p)
q=[(p[i][0],i) for i in range(N)]
q.sort()
p=[p[q[i][1]] for i in range(N)]
ans=0
for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])-pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS and not (abs(cmath.phase(p[j][1]/p[i][1])))<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])-pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])+pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS and not (abs(cmath.phase(p[j][1]/p[i][1])))<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])+pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS :
            z+=p[j][1]
    ans=max(ans,abs(z))

print(ans)

Solution (Python):
import math
import cmath
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

atan = math.atan2
deg = math.degrees
eps = 1e-9

N = int(input())
arg = []
XY = []
for i in range(N):
    x, y = map(int, input().split())
    arg.append((deg(atan(y, x)), x, y))
arg.sort()
arg += [(th + 360, x, y) for th, x, y in arg]

dth = 360 / (5000)
th = 0
ans = 0
for _ in range(5001):
    X = 0
    Y = 0
    for a, x, y in arg:
        if abs(th - a) < 90 + eps:
            X += x
            Y += y
    ans = max(ans, X ** 2 + Y ** 2)
    th += dth

print("{:.40f}".format(ans**0.5))

Solution (Python):
from math import atan2
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: atan2(x[1], x[0]))
ans = 0
for lp in range(n):
    for rg in range(n):
        lf = lp
        x, y = l[lf]
        lf += 1
        if lf == n:
            lf = 0
        while lf != rg:
            x += l[lf][0]
            y += l[lf][1]
            lf += 1
            if lf == n:
                lf = 0
        ans = max(ans, (x ** 2 + y ** 2) ** .5)
print(ans)

Solution (Python):
from math import *
n = int(input())
engine = [list(map(int, input().split())) for i in range(n)]

args = []
for i in range(n):
    x, y = engine[i]
    if x == 0:
        if y < 0:
            args.append((-pi/2, x, y))
        elif y > 0:
            args.append((pi/2, x, y))

    elif y == 0:
        if x > 0:
            args.append((0, x, y))
        elif x < 0:
            args.append((pi, x, y))

    else:
        args.append((atan2(y, x), x, y))

args.sort()
l = len(args)
args = args[:] + args[:]
ans = 0
for i in range(1, l+1):
    for j in range(l):
        x, y = 0, 0
        for k in range(j, j+i):
            x += args[k][1]
            y += args[k][2]
        ans = max(ans, (x**2+y**2)**(1/2))

print(ans)