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):
import numpy as np

N = int(input())
XY =  np.array([list(map(int,input().split())) for _ in [0]*N])

ans = 0
for m in range(100):
    th = 2*np.pi*m/100
    r = np.array([np.cos(th),np.sin(th)])
    check = XY.dot(r)>=0
    ans = max(ans,np.linalg.norm(np.sum(XY[check],axis=0)))
print(ans)

Solution (Python):
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
Sxy = np.vstack((np.zeros(2),np.cumsum(XY,axis=0)))
i=0
j=1
pr = 0
while i<N:
        r = n(Sxy[min(j,N)]-Sxy[i] + Sxy[max(0,j-N)])
        if r>=pr and j<i+N+1 : j+=1
        else:
            i += 1
            j = max(j-1,i+1)
            r = 0
        ans = max(ans,r)
        pr = r
print(ans)

Solution (Python):
from math import atan2, pi

N = int(input())
dxy = []
for _ in range(N) :
    x, y = map(int, input().split())
    dxy.append((atan2(y, x), x, y))

dxy.sort()
for i in range(N) :
    dxy.append((dxy[i][0] + 2 * pi, dxy[i][1], dxy[i][2]))

M = 0
E = 1e-6
for i in range(N) :
    d, x, y = dxy[i][0], 0, 0
    for j in range(i, 2 * N) :
        if dxy[j][0] - d > pi + E :
            break
        x += dxy[j][1]
        y += dxy[j][2]
        M = max(M, x * x + y * y)
print(M ** 0.5)

Solution (Python):
from math import hypot, atan2

N = int(input())
engines = [tuple(map(int, input().split())) for _ in range(N)]

engines.sort(key=lambda z: atan2(z[1], z[0]))

ans = 0
for L in range(N):
    for R in range(N):
        if L <= R:
            x, y = map(sum, zip(*engines[L:R+1]))
        else:
            x, y = map(sum, zip(*(engines[:R+1]+engines[L:])))
        dist = hypot(x, y)
        ans = max(ans, dist)

print(ans)

Solution (Python):
from math import hypot

N = int(input())
engines = [tuple(map(int, input().split())) for _ in range(N)]

def dot(x1, y1, x2, y2):
    return x1*x2 + y1*y2
def cross(x1, y1, x2, y2):
    return x1*y2 - y1*x2

def getDistMax(xBase, yBase):
    x1s, y1s, x2s, y2s = [], [], [], []
    x, y = 0, 0
    for dx, dy in engines:
        d = dot(xBase, yBase, dx, dy)
        if d > 0:
            x, y = x+dx, y+dy
        elif d == 0:
            c = cross(xBase, yBase, dx, dy)
            if c > 0:
                x1s.append(dx)
                y1s.append(dy)
            else:
                x2s.append(dx)
                y2s.append(dy)
    ans = max(hypot(x, y), hypot(x+sum(x1s), y+sum(y1s)), hypot(x+sum(x2s), y+sum(y2s)))
    return ans

ans = 0
for x, y in engines:
    ds = []
    ds.append(getDistMax( x,  y))
    ds.append(getDistMax(-y,  x))
    ds.append(getDistMax(-x, -y))
    ds.append(getDistMax( y, -x))
    ans = max(ans, max(ds))

print(ans)

Solution (Python):
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
XY = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def calc(bx, by):
    base = math.atan2(bx, by)

    d1 = []
    d2 = []
    for x, y in XY:
        deg = (math.atan2(x, y) - base) % (math.pi * 2)
        if deg < math.pi:
            d1.append((x, y))
        else:
            d2.append((x, y))

    x1 = 0
    y1 = 0
    x2 = 0
    y2 = 0
    for x, y in d1:
        x1 += x
        y1 += y
    for x, y in d2:
        x2 += x
        y2 += y

    return max(math.sqrt(x1 ** 2 + y1 ** 2), math.sqrt(x2 ** 2 + y2 ** 2))


ans = 0
for x, y in XY:
    ans = max(ans, calc(x, y))
print(ans)

Solution (Python):
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
Sxy = np.vstack((np.zeros(2),np.cumsum(XY,axis=0)))
for i in range(N):
    for j in range(i+1,i+N+1):
        r = n(Sxy[min(j,N)]-Sxy[i] + Sxy[max(0,j-N)])
        ans = max(ans,r)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
for i in range(N):
    for j in range(i+1,i+N+1):
        r = n(XY[i:j].sum(axis=0)+XY[:max(0,j-N)].sum(axis=0))
        ans = max(ans,r)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
XY = np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
n = np.linalg.norm
s = np.sum
for i in range(N):
    for j in range(i+1,i+N+1):
        r = n(s(XY[i:j],axis=0)+s(XY[:max(0,j-N)],axis=0))
        ans = max(ans,r)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
XY =  np.array([list(map(int,input().split())) for _ in [0]*N])
th = np.arctan2(XY[:,1],XY[:,0])
XY = XY[th.argsort()]
ans = 0
for i in range(N):
    for j in range(i+1,i+N+1):
        r = np.linalg.norm(XY[i:j].sum(axis=0)+XY[:max(0,j-N)].sum(axis=0))
        ans = max(ans,r)
print(ans)

Solution (Python):
import sys
from math import *

sys.setrecursionlimit(10 ** 6)

def main():
    n = int(input())
    en = []
    n0 = n
    for _ in range(n0):
        x, y = map(int, input().split())
        if (x, y) == (0, 0):
            n -= 1
            continue
        en.append([atan2(y, x), x, y])
    en.sort()


    ans = 0
    for l in range(n):
        sx = sy = 0
        arg_l = en[l][0]
        r = l
        for _ in range(n):
            if (en[r][0] - arg_l) % (2 * pi) > pi: break
            sx += en[r][1]
            sy += en[r][2]
            ans = max(ans, (sx ** 2 + sy ** 2))
            r = (r + 1) % n
    print(ans ** 0.5)

main()

Solution (Python):
def f_engines():
    import math
    N = int(input())
    
    Engines = sorted([[int(i) for i in input().split()] for j in range(N)],
                     key=lambda x: math.atan2(x[1], x[0])) * 2

    ans = 0
    for head in range(N):
        
        for tail in range(head, head + N):
            x, y = 0, 0
            for i in range(head, tail + 1):
                dx, dy = Engines[i]
                x += dx
                y += dy
            ans = max(ans, x * x + y * y)
    return math.sqrt(ans)

print(f_engines())

Solution (Python):
import cmath
import itertools
n = int(input())
C = sorted([complex(*map(int,input().split())) for _ in range(n)], key=cmath.phase)
score = 0
for i,j in itertools.product(range(n),range(n)):
    if i>j: continue
    score = max((score,abs(sum(C[:i]+C[j:])),abs(sum(C[i:j]))))
print(score)

Solution (Python):
import numpy as np

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

def naiseki(a,b):
    if (a[0]*b[0]+a[1]*b[1])>0.0:
        return True
    else:
        return False
    
ans=0

for i in range(1001):
    xl=np.cos(np.pi*2.0*i/1000.0)
    yl=np.sin(np.pi*2.0*i/1000.0)
    x=0
    y=0
    for j in range(n):
        if naiseki([xl,yl],xy[j]):
            x+=xy[j][0]
            y+=xy[j][1]
    ans=max(ans,np.sqrt(x**2+y**2))
print(ans)

Solution (Python):
import cmath
import itertools

n = int(input())
C = sorted([complex(*map(int,input().split())) for _ in range(n)], key=cmath.phase)
score = 0
for i,j in itertools.product(range(n),range(n)):
    if i>j: continue 
    score = max(score,abs(sum(C[:i]+C[j:])))
    score = max(score,abs(sum(C[i:j])))
print(score)

Solution (Python):
import math
n=int(input())
e=[]
for i in range(n):
    x,y=map(int,input().split())
    if (x,y)==(0,0):
        continue
    else:
        t=math.atan2(y,x)
        e.append((x,y,t))
e.sort(key=lambda x:x[2])
n=len(e)

e+=e
a=[(0,0)]
ans=0
for x,y,t in e:
    a+=[(a[-1][0]+x,a[-1][1]+y)]
for l in range(n*2):
    for r in range(l,n*2):
        if r-l>n:
            continue
        else:
            x,y=a[r]
            w,z=a[l]
            ans=max((x-w)**2+(y-z)**2,ans)
print(ans**0.5 if n>0 else 0)

Solution (Python):
import math
n=int(input())
e=[]
for i in range(n):
    x,y=map(int,input().split())
    if (x,y)==(0,0):
        continue
    else:
        t=math.atan2(y,x)
        e.append((x,y,t))
e.sort(key=lambda x:x[2])
n=len(e)

e+=e
a=[(0,0)]
ans=0
for x,y,t in e:
    a+=[(a[-1][0]+x,a[-1][1]+y)]

for l in range(n*2):
    for r in range(l,n*2):
        if r-l>n:
            continue
        else:
            x,y=a[r]
            w,z=a[l]
            ans=max((x-w)**2+(y-z)**2,ans)
print(ans**0.5 if n>0 else 0)

Solution (Python):
import math
N=int(input())
x=[0 for i in range(N)]
y=[0 for i in range(N)]
for i in range(N):
    x[i],y[i]=map(int,input().split())
M=10000
ans=0
for i in range(M):
    Vx=math.cos(2*i*math.pi/M)
    Vy=math.sin(2*i*math.pi/M)
    X=0
    Y=0
    for j in range(N):
        if Vx*x[j]+Vy*y[j]>=0:
            X+=x[j]
            Y+=y[j]
    ans=max(ans,X*X+Y*Y)
print(math.sqrt(ans))

Solution (Python):

import math
N = int(input())
XY = [list(map(int,input().split())) for _ in  range(N)]
for i in range(N):
    XY[i].append(math.atan2(XY[i][1],XY[i][0]))

XY.sort(key = lambda x:x[2])
ans = 0
tmp = [0,0]
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
ans = 0
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
for i in range(N):
    if XY[i][2] < 0:
        XY[i][2] = -math.pi-XY[i][2]
    else:
        XY[i][2] = math.pi - XY[i][2]
        

XY.sort(key = lambda x:x[2])
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
        
print(ans)

Solution (Python):

import math
N = int(input())
XY = [list(map(int,input().split())) for _ in  range(N)]
for i in range(N):
    XY[i].append(math.atan2(XY[i][1],XY[i][0]))

XY.sort(key = lambda x:x[2])
ans = 0
tmp = [0,0]
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
ans = 0
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
for i in range(N):
    if XY[i][2] < 0:
        XY[i][2] = -math.pi-XY[i][2]
    else:
        XY[i][2] = math.pi - XY[i][2]
        

XY.sort(key = lambda x:x[2])
ruisekiwa_x = [0] * N
ruisekiwa_y = [0] * N
ruisekiwa_x[0] = XY[0][0]
ruisekiwa_y[0] = XY[0][1]

for i in range(1,N):
    ruisekiwa_x[i] = ruisekiwa_x[i-1] + XY[i][0]
    ruisekiwa_y[i] = ruisekiwa_y[i-1] + XY[i][1]
    
for i in range(N):
    for j in range(i,N):
        if i>0: 
            tmp[0] = ruisekiwa_x[j] - ruisekiwa_x[i-1]
            tmp[1] = ruisekiwa_y[j] - ruisekiwa_y[i-1]
        else:
            tmp[0] = ruisekiwa_x[j] 
            tmp[1] = ruisekiwa_y[j] 
            
            
        ans = max(ans,math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1]))
        
print(ans)

Solution (Python):

import math
N = int(input())
XY = [list(map(int,input().split())) for _ in  range(N)]

ans = 0
L = 10**5
for i in range(L):
    x,y = [math.cos(2*math.pi*i/L),math.sin(2*math.pi*i/L)]
    tmpx,tmpy = 0,0
    for j in range(N):
        xj,yj = XY[j]
        if x*xj + y*yj > 0:
            tmpx += xj
            tmpy += yj
            
    ans = max(ans,math.sqrt(tmpx*tmpx+tmpy*tmpy))
    
print(ans)

Solution (Python):
import sys
import math

n = int(sys.stdin.readline().rstrip())
point = []
for i in range(n):
    ax = list(map(int, sys.stdin.readline().rstrip().split()))
    if ax[0] != 0 or ax[1] != 0:
        point.append(ax)

result = 0
plen = len(point)
if plen == 0:
    print(0)
    exit()

point = sorted(point, key=lambda x: math.atan2(x[1], x[0]))

point = point + point
for i in range(plen):
    maxdig = 0
    maxp = [0, 0]
    for j in range(i, i + plen):
        tmpp = (maxp[0] + point[j][0]) ** 2 + (maxp[1] + point[j][1]) ** 2
        if maxdig > tmpp:
            if result < maxdig:
                result = maxdig
            break
        else:
            maxdig = tmpp
            maxp[0] += point[j][0]
            maxp[1] += point[j][1]
            if j == i + plen -1 and result < maxdig:
                result = maxdig


print(result ** 0.5)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
points = []

for _ in range(N):
    x,y = inpl()
    t = math.atan2(y,x)
    points.append((t,x,y))

points.sort()

ans = 0
for s,[theta,x,y] in enumerate(points):
    tmpx = tmpy = 0
    for t in range(s,s+N):
        _,tx,ty = points[t%N]
        tmpx += tx
        tmpy += ty
        ans = max(ans,tmpx**2 + tmpy**2)

print(math.sqrt(ans))

Solution (Python):
import math
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]


ans = 0
for i in range(100):
  x=math.cos(2*math.pi*i/100)
  y=math.sin(2*math.pi*i/100)
  x1 = 0
  y1 = 0
  for j in range(N):  
    if x * A[j][0] + y * A[j][1] >= 0:
      x1 += A[j][0]
      y1 += A[j][1]
  ans1 = (x1 ** 2 + y1 ** 2 ) ** (1/2)
  ans = max(ans, ans1)
  
print(ans)

Solution (Python):
import numpy as np

n=int(input())

def div2(x,y):
    if x>0:
        return (1,y/x)
    elif x<0:
        return (-1,y/x)
    else:
        if y>0:
            return (-1,-float("inf"))
        else:
            return (1,-float("inf"))
    

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

L.sort(key=lambda x:div2(x[0],x[1]))

m=0
for i in range(n):
    for j in range(i,n):
        x0=y0=0
        x1=y1=0
        for k in range(n):
            if i<=k<=j:
                x0+=L[k][0]
                y0+=L[k][1]
            else:
                x1+=L[k][0]
                y1+=L[k][1]
        m=max(m,x0**2+y0**2,x1**2+y1**2)

print('{:.12f}'.format(np.sqrt(m)))

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(100):
    x=math.cos(2*math.pi*i/100)
    y=math.sin(2*math.pi*i/100)
    ax,ay=0,0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(100):
    x=math.cos(2*math.pi*i/100)
    y=math.sin(2*math.pi*i/100)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(100):
    x=math.cos(2*math.pi*i/100)
    y=math.sin(2*math.pi*i/100)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(360):
    x=math.cos(2*math.pi*i/360)
    y=math.sin(2*math.pi*i/360)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(500):
    x=math.cos(2*math.pi*i/500)
    y=math.sin(2*math.pi*i/500)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(1000):
    x=math.cos(2*math.pi*i/1000)
    y=math.sin(2*math.pi*i/1000)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):
import sys,math
input=sys.stdin.readline
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(10000):
    x=math.cos(2*math.pi*i/10000)
    y=math.sin(2*math.pi*i/10000)
    ax=0
    ay=0
    for dx,dy in xy:
        if x*dx+y*dy>=0:
            ax+=dx
            ay+=dy
    ans=max(ans,(ax**2+ay**2)**0.5)
print(ans)

Solution (Python):




def get_convex_hull(points):
    def det(p, q):
        return (p.conjugate()*q).imag
    points.sort(key=lambda x: (x.real, x.imag))
    ch = []
    for p in points:
        while len(ch) > 1:
            v_cur = ch[-1]-ch[-2]
            v_new = p-ch[-2]
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    t = len(ch)
    for p in points[-2::-1]:
        while len(ch) > t:
            v_cur = ch[-1]-ch[-2]
            v_new = p-ch[-2]
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    return ch[:-1]


N = int(input())
XY = [complex(*map(int, input().split())) for _ in range(N)]
ps = [complex(0, 0)]
for p in XY:
    ps_new = ps[:]
    for p_ in ps:
        ps_new.append(p+p_)
    ps = get_convex_hull(ps_new)
ans = 0
for p in ps:
    ans = max(ans, abs(p))
print(ans)

Solution (Python):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

import math

def sol():
    N = int(input())
    engine = [tuple(map(int, input().split())) for _ in range(N)]

    ans = 0

    for direct in range(0, 1000):
        direct = 2 * math.pi / 999 * direct
        u, v = math.cos(direct), math.sin(direct)

        length = [0, 0]
        for x, y in engine:
            if u * x + v * y >= 0:
                length[0] += x
                length[1] += y

        ans = max(ans, length[0]**2 + length[1]**2)

    print(ans**0.5)

sol()

Solution (Python):


def get_convex_hull(points):
    def det(p, q):
        return p[0] * q[1] - p[1] * q[0]
    def sub(p, q):
        return (p[0] - q[0], p[1] - q[1])
    points.sort()
    ch = []
    for p in points:
        while len(ch) > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(p, ch[-2])
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    t = len(ch)
    for p in points[-2::-1]:
        while len(ch) > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(p, ch[-2])
            if det(v_cur, v_new) > 0:
                break
            ch.pop()
        ch.append(p)
    return ch[:-1]
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
ps = [(0, 0)]
for x, y in XY:
    ps_new = ps[:]
    for x_, y_ in ps:
        ps_new.append((x+x_, y+y_))
    ps = get_convex_hull(ps_new)
ans = 0
for x, y in ps:
    ans = max(ans, x*x+y*y)
print(ans ** 0.5)

Solution (Python):
import cmath
import math

N = int(input())
pc = []
for i in range(N):
  x, y = map(int, input().split())
  c = x + y*1j
  p = cmath.phase(c)
  pc.append([p, c])
pc = sorted(pc, key=lambda x: x[0])

ps = [pc[i][0] for i in range(N)]
cs = [pc[i][1] for i in range(N)]

def L(i, j, N):
  if i<j:
    return list(range(i, j))
  else:
    return list(range(0, j)) + list(range(i+1, N))

s = 0
m = 0

for start in range(N):
  for end in range(N):
    s = 0
    
    for k in L(start,end,N):
      s += cs[k]
    m = max(m, abs(s))
s = 0
for k in range(N):
  s += cs[k]
  m = max(m, abs(s))
print(m)

Solution (Python):
import cmath
import math

N = int(input())
pc = []
for i in range(N):
  x, y = map(int, input().split())
  c = x + y*1j
  p = cmath.phase(c)
  pc.append([p, c])
pc = sorted(pc, key=lambda x: x[0])

ps = [pc[i][0] for i in range(N)]
cs = [pc[i][1] for i in range(N)]

def L(i, j, N):
  if i<j:
    return list(range(i, j))
  else:
    return list(range(0, j)) + list(range(i+1, N))

s = 0
m = 0

for start in range(N):
  for end in range(N):
    s = 0
    
    for k in L(start,end,N):
      s += cs[k]
    m = max(m, abs(s))
s = 0
for k in range(N):
  s += cs[k]
  m = max(m, abs(s))
print(m)

Solution (Python):
from math import sin,cos,pi
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for n in range(10**5):
    Rx = cos(2*pi*n/10**5)
    Ry = sin(2*pi*n/10**5)
    X = 0
    Y = 0
    for x,y in xy:
        if Rx*x+Ry*y > 0:
            X += x
            Y += y
    ans = max(ans,(X**2+Y**2)**0.5)
print(ans)

Solution (Python):
import math

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

k=6*10**5+1050
t=2*math.pi/k
ANS=0
for i in range(k):
    X=math.sin(t*i)
    Y=math.cos(t*i)

    ANSX=0
    ANSY=0

    for x,y in P:
        if X*x+Y*y>0:
            ANSX+=x
            ANSY+=y

    ANS=max(ANS,ANSX**2+ANSY**2)

print(math.sqrt(ANS))

Solution (Python):
import math

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

def div2(x,y):
    if x>0:
        return (1,y/x)
    elif x<0:
        return (-1,y/x)
    else:
        if y>0:
            return (-1,-float("inf"))
        else:
            return (1,-float("inf"))

P.sort(key=lambda x:div2(x[0],x[1]))

ANS=0

for i in range(N):
    for j in range(i,N):
        x0=y0=0
        x1=y1=0

        for k in range(N):
            if i<=k<=j:
                x0+=P[k][0]
                y0+=P[k][1]
            else:
                x1+=P[k][0]
                y1+=P[k][1]

        ANS=max(ANS,x0**2+y0**2,x1**2+y1**2)

print(math.sqrt(ANS))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = S()
    t = S()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return


def B():
    a,b = LI()
    for i in range(10000):
        if 1+i*a-i >= b:
            print(i)
            return
    return


def C():
    n = I()
    a = LI()
    ans = 0
    r = 1
    for l in range(n):
        if r == l:
            r += 1
        while r < n and a[r-1] >= a[r]:
            r += 1
        ans = max(ans, r-l-1)
    print(ans)
    return


def D():
    n = I()
    print(n*(n-1)>>1)
    return


def E():
    def dfs(x,p):
        if dp[x] != None:
            return dp[x]
        dp[x] = -1
        for y in v[x]:
            if p[y]:
                dp[x] = float("inf")
                break
            p[y] = 1
            dp[x] = max(dp[x], dfs(y,p)+1)
            p[y] = 0
        return dp[x]

    n = I()
    a = LIR(n)
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1
    m = n*(n-1)
    v = [[] for i in range(m)]
    for i in range(n):
        p = n*min(i, a[i][0]) + max(i, a[i][0])
        for j in range(n-2):
            p_ = n*min(i, a[i][j+1]) + max(i, a[i][j+1])
            v[p_].append(p)
            p = p_
    dp = defaultdict(lambda : None)
    for i in range(m):
        if not v[i]:
            dp[i] = 1
    ans = 1
    p = [0]*m
    for x in range(m):
        p[x] = 1
        if ans < dfs(x,p):
            ans = dp[x]
        p[x] = 0
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)
    return


def E_():
    n = I()
    a = LIR(n)
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1
    m = n*(n-1)
    v = [[] for i in range(m)]
    f = [0]*m
    for i in range(n):
        p = n*min(i, a[i][0]) + max(i, a[i][0])
        for j in range(n-2):
            p_ = n*min(i, a[i][j+1]) + max(i, a[i][j+1])
            v[p].append(p_)
            f[p] += 1
            p = p_
    q = []
    for i in range(m):
        heappush(q,(f[i],i))
    if q[0][0]:
        print(-1)
        return
    d = [1 if not f[i] else -1 for i in range(m)]
    bfs = [1]*m
    while q:
        fx, x = heappop(q)
        if not bfs[x]:
            continue
        bfs[x] = 0
        for y in v[x]:
            d[y] = d[x]+1
            f[y] -= 1
            if not f[y]:
                heappush(q,(0,y))
    print(d)
    return

def F():
    def f(x,y):
        if x == 0:
            if y < 0:
                return -float("inf")
            else:
                return float("inf")
        else:
            return y/x

    def g(x,y):
        d = math.degrees(math.atan(f(x,y)))
        if x < 0:
            d += 180
        return d
    n = I()
    p = LIR(n)
    for i in range(n):
        p[i].append(g(*p[i]))
    p.sort(key = lambda x : x[2])
    for i in range(n):
        p.append(p[i])
    ans = 0
    for i in range(n):
        d = [0,0]
        for j in range(i,n+i):
            d[0] += p[j][0]
            d[1] += p[j][1]
            dist = d[0]**2+d[1]**2
            if ans < dist:
                ans = dist
    print(ans**0.5)
    return


if __name__ == "__main__":
    F()

Solution (Python):
import math

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

def div2(x,y):
    if x>0:
        return (1,y/x)
    elif x<0:
        return (-1,y/x)
    else:
        if y>0:
            return (-1,-float("inf"))
        else:
            return (1,-float("inf"))

P.sort(key=lambda x:div2(x[0],x[1]))

ANS=0

for i in range(N):
    for j in range(i,N):
        x0=y0=0
        x1=y1=0

        for k in range(N):
            if i<=k<=j:
                x0+=P[k][0]
                y0+=P[k][1]
            else:
                x1+=P[k][0]
                y1+=P[k][1]

        ANS=max(ANS,x0**2+y0**2,x1**2+y1**2)

print(math.sqrt(ANS))

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import math
N=i1()
x=[]
for i in range(N):
 z=i2()
 x.append([math.atan2(z[1],z[0]),z])

x.sort()
a=0
for i in range(N):
 s1=[0,0]
 aa=0
 for j in range(N):
   y1=(i+j)%N
   s1[0]+=x[y1][1][0]
   s1[1]+=x[y1][1][1]
   aa=max(aa,math.sqrt(s1[0]**2+s1[1]**2))
   
 a=max(a,aa)
 
print('{:.12f}'.format(a))

Solution (Python):

import math



def main():
    N = int(input())
    E = []
    for i in range(N):
        x, y = map(int,input().split())
        E.append((math.atan2(y,x),x,y))
    E = sorted(E) * 2

    answer = 0
    for i in range(N):
        x = 0
        y = 0
        for j in range(i, i+N):
            x += E[j][1]
            y += E[j][2]
            answer = max(answer, x * x + y * y)

    answer = math.sqrt(answer)
    print(answer)

if __name__ == "__main__":
    main()

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import math
N=i1()
x=[]
for i in range(N):
 z=i2()
 x.append([math.atan2(z[1],z[0]),z])

x.sort()
a=0
for i in range(N):
 s1=[0,0]
 aa=0
 for j in range(N):
   y1=(i+j)%N
   s1[0]+=x[y1][1][0]
   s1[1]+=x[y1][1][1]
   aa=max(aa,math.sqrt(s1[0]**2+s1[1]**2))
   
 a=max(a,aa)
 
print(a)