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 sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans

Solution (Python):
import itertools
N = int(input())
XY = [[int(_) for _ in input().split()] for _ in range(N)]
xy1 = []
xy2 = []
xy3 = []
xy4 = []
for x, y in XY:
    if x >= 0:
        if y >= 0:
            xy1 += [[x, y]]
        else:
            xy4 += [[x, y]]
    else:
        if y >= 0:
            xy2 += [[x, y]]
        else:
            xy3 += [[x, y]]
xy1.sort(key=lambda xy: float('inf') if xy[0] == 0 else xy[1] / xy[0])
xy2.sort(key=lambda xy: xy[1] / xy[0])
xy3.sort(key=lambda xy: xy[1] / xy[0])
xy4.sort(key=lambda xy: -float('inf') if xy[0] == 0 else xy[1] / xy[0])
XY = xy1 + xy2 + xy3 + xy4
N = len(XY)
XY *= 2
acc = list(
    itertools.accumulate(XY, func=lambda a, b: [a[0] + b[0], a[1] + b[1]]))
ans = 0
for i in range(N):
    for j in range(i + 1, i + N + 1):
        x = acc[j][0] - acc[i][0]
        y = acc[j][1] - acc[i][1]
        ans = max(ans, x**2 + y**2)
print(ans**0.5)

Solution (Python):
import numpy as np
N = int(input())
X = []
Y = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
X = np.array(X)
Y = np.array(Y)
theta = np.arctan2(X, Y)
index = theta.argsort()
X = X[index]
Y = Y[index]
X = np.tile(X, 2)
Y = np.tile(Y, 2)
Xcum = X.cumsum()
Ycum = Y.cumsum()
ans = (Ycum-Ycum[:, None])**2+(Xcum-Xcum[:, None])**2
m = 0
for i in range(N*2):
    m = max(m, ans[i, i:i+N+1].max())
print(m**0.5)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
XY = np.array(read().split(),np.int64)

X = XY[::2]; Y = XY[1::2]
theta = np.arctan2(Y,X)
ind = theta.argsort(); X = X[ind]; Y = Y[ind]


X = np.tile(X,2)
Y = np.tile(Y,2)
Xcum = np.cumsum(X)
Ycum = np.cumsum(Y)

answer = 0
for items in range(1,N+1):
    x = Xcum[items:] - Xcum[:-items]
    y = Ycum[items:] - Ycum[:-items]
    L = (x*x+y*y).max()
    if answer < L:
        answer = L

answer **= 0.5
print(answer)

Solution (Python):
n = int(input())
from cmath import phase
xy = sorted([list(map(int,input().split())) for i in range(n)],key=lambda x: phase(x[0]+x[1]*1j))

xy += xy

ans = 0
for l in range(n):
    a = [0,0] 
    for r in range(l,min(2*n,l+n)):
        a[0] += xy[r][0]
        a[1] += xy[r][1]
        ans = max(ans,abs(a[0]+a[1]*1j))
print(ans)

Solution (Python):
import math

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



for i in range(n):
    x, y = map(int, input().split( ))
    rad = math.atan2(x, y)
    P.append([rad, x, y])

P.sort()
P = P + P 


x0 = 0
y0 = 0

mx = 0

for i in range(n):
    vx = 0
    vy = 0
    for j in range(n):
        vx += P[i+j][1]
        vy += P[i+j][2]
        v = vx**2 + vy**2
        mx = max(v,mx)
print(math.sqrt(mx))

Solution (Python):
from math import atan2, pi

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

for _ in range(n):
    x, y = map(int, input().split())
    r = atan2(y, x)
    if r < 0:
        r += pi * 2
    e.append([r, x, y])

e.sort()

ans = 0
for i in range(n):
    e.append([e[i][0] + pi * 2, e[i][1], e[i][2]])
    ans = max(ans, (e[i][1] ** 2 + e[i][2] ** 2) ** 0.5)

if n == 1:
    print(ans)
    exit()

for L in range(n):
    x = e[L][1]
    y = e[L][2]
    for R in range(L+1, L+n):
        x += e[R][1]
        y += e[R][2]
        ans = max(ans, (x ** 2 + y ** 2) ** 0.5)

print(ans)

Solution (Python):
import math

def f(a,b):
    if a+90 >= b and a-90 <= b:
        return True
    if a+270 <= b and b <= 180:
        return True
    if a-270 >= b and b >= -180:
        return True
    return False

n = int(input())

xy = []
ang = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
    ang.append(math.degrees(math.atan2(y,x)))




res = 0
p = -180.0
d = 360.0/1000
for _ in range(1000):
    xx = 0.0
    yy = 0.0
    for i,e in enumerate(ang):
        if f(p,e):
            xx += xy[i][0]
            yy += xy[i][1]
    p += d
    tmp = (xx**2+yy**2)**0.5

    res = max(tmp,res)
print(res)

Solution (Python):
import math

N = int(input())
P = []
for _ in range(N):
    P.append([int(n) for n in input().split()])

R2 = 0

for i in range(180):
    theta = 2 * math.pi * i / 180
    a, b = math.cos(theta), math.sin(theta)
    X, Y = 0, 0
    for x, y in P: 
        if a*x+b*y > 0: 
            X += x
            Y += y
    r2 = X**2+Y**2
    if r2 > R2:
        R2 = r2

print(math.sqrt(R2))

Solution (Python):
1
import math

N = int(input())
P = []
for _ in range(N):
    P.append([int(n) for n in input().split()])

R2 = 0

for i in range(360):
    theta = 2 * math.pi * i / 360
    a, b = math.cos(theta), math.sin(theta)
    X, Y = 0, 0
    for x, y in P: 
        if a*x+b*y > 0: 
            X += x
            Y += y
    r2 = X**2+Y**2
    if r2 > R2:
        R2 = r2

print(math.sqrt(R2))

Solution (Python):
import math
 
N = int(input())
V = []
for _ in range(N):
    V.append([ int(n) for n in input().split() ])
 
R2 = 0
for i in range(100): 
    theta = 2 * math.pi * i / 100  
    a, b = math.cos(theta), math.sin(theta)  
    X, Y = 0, 0
    for x, y in V: 
        if a*x+b*y > 0: 
            X += x
            Y += y
    r2 = X**2+Y**2
    if r2 > R2:
        R2 = r2
 
print(math.sqrt(R2))

Solution (Python):
def f_f():
    import numpy as np

    n = int(input())
    x, y = np.array([input().split() for _ in range(n)], dtype="int64").T

    a = np.arctan2(x, y)
    i = a.argsort()
    x, y, a = x[i], y[i], a[i]

    x, y = np.concatenate([x, x]), np.concatenate([y, y])
    a = np.concatenate([a, a+2*np.pi])

    xcs, ycs = x.cumsum(), y.cumsum()
    items = np.arange(1, n+1)[None,:]
    l = np.arange(n)[:,None]

    dx = xcs[l+items-1]-xcs[l]+x[l]
    dy = ycs[l+items-1]-ycs[l]+y[l]

    print((dx*dx+dy*dy).max()**0.5)

if __name__ == "__main__":
    f_f()

Solution (Python):
import math
N = int(input())
n = 72

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
from math import atan2, hypot

n = int(input())
xy = []
for i in range(n):
    x,y = map(int, input().split())
    theta = atan2(y,x)
    xy.append((theta, y, x))
xy.sort()
xy += xy
cs = [(0,0)]
for _, x, y in xy:
    cs.append((cs[-1][0]+x, cs[-1][1]+y))

ans = 0
for i in range(n):
    for j in range(i+1, i+n+1):
        x1, y1 = cs[i]
        x2, y2 = cs[j]
        ans = max(ans, hypot(x1-x2, y1-y2))
print(ans)

Solution (Python):
import sys
import math
from collections import deque

input = sys.stdin.readline


def solve(n, x_y_list):
    radians = [(math.atan2(y, x), x, y) for x, y in x_y_list]
    radians.sort()
    radians = radians + radians

    max_square_distance = 0
    for start in range(n):
        sum_x = sum_y = 0
        for i in range(n):
            _, x, y = radians[start + i]
            sum_x += x
            sum_y += y
            square_distance = sum_x ** 2 + sum_y ** 2
            if max_square_distance < square_distance:
                max_square_distance = square_distance
    return math.sqrt(max_square_distance)


if __name__ == '__main__':
    n = int(input())
    x_y_list = [tuple(map(int, input().split())) for _ in range(n)]

    answer = solve(n, x_y_list)
    print(answer)

Solution (Python):
from math import sqrt

N = int(input())
engine = {}
tan_key = []
tan_key_infty = []
for i in range(N):
    x, y = map(int,input().split())
    if x != 0:
        tan = y / x
    else:
        tan = -10**10

    if tan in tan_key:
        engine[tan].append((x, y))
    else:
        engine[tan] = [(x, y)]
        tan_key.append(tan)
tan_key.sort()





left_coordinate = [0, 0]
right_coordinate = [0, 0]
for tan in tan_key:
    for x, y in engine[tan]:
        if x > 0:
            right_coordinate[0] += x
            right_coordinate[1] += y
        elif x < 0:
            left_coordinate[0] += x
            left_coordinate[1] += y

max_left = sqrt(left_coordinate[0] ** 2 + left_coordinate[1] ** 2)
max_right = sqrt(right_coordinate[0] ** 2 + right_coordinate[1] ** 2)




d = 2 * len(tan_key) - 1
for i in range(d):
    if i % 2 == 0:
        for x, y in engine[tan_key[i // 2]]:
            if x > 0:
                left_coordinate[0] += x
                left_coordinate[1] += y
            elif x < 0:
                right_coordinate[0] += x
                right_coordinate[1] += y
            elif x == 0:
                if y > 0:
                    right_coordinate[0] += x
                    right_coordinate[1] += y
                else:
                    left_coordinate[0] += x
                    left_coordinate[1] += y

    else:
        for x, y in engine[tan_key[(i + 1) // 2]]:
            if x > 0:
                right_coordinate[0] -= x
                right_coordinate[1] -= y
            elif x < 0:
                left_coordinate[0] -= x
                left_coordinate[1] -= y

    max_left = max(max_left, sqrt(left_coordinate[0] ** 2 + left_coordinate[1] ** 2))
    max_right = max(max_right, sqrt(right_coordinate[0] ** 2 + right_coordinate[1] ** 2))


    

print(max(max_left, max_right))

Solution (Python):
import numpy as np

n = int(input())
x,y = np.array([list(map(int,input().split())) for _ in range(n)]).T


def isin90deg(v1, v2):
    if np.dot(v1, v2) >= 0 : return 1
    else: return 0


def is90deg(v1, v2):
    if np.dot(v1, v2) == 0 : return 1
    else: return 0

ans = []
for i in range(n):
    
    tv, nv1 = np.array([x[i],y[i]]), np.array([y[i],-x[i]])
    nv2 = - nv1
    
    
    for nv in [nv1, nv2]:
        sum,posi,nega = np.array([0,0]), np.array([0,0]), np.array([0,0])
        for j in range(n):
            v = np.array([x[j],y[j]])
            if isin90deg(v,nv): sum += v
            if is90deg(v,nv) and isin90deg(v,tv): posi += v
            if is90deg(v,nv) and not isin90deg(v,tv): nega += v
        
        ans.append(np.linalg.norm(sum, ord=2))
        ans.append(np.linalg.norm(sum - posi, ord=2))
        ans.append(np.linalg.norm(sum - nega, ord=2))

print(max(ans))

Solution (Python):
import sys

import math
import numpy as np

def main():
    n = int(input())
    vec = [tuple(map(int, input().split())) for i in range(n)]
    vec.sort(key=lambda x: math.atan2(x[1], x[0]))

    maxx = 0
    for i in range(n):
        for j in range(1, n+1):
            now = [0, 0]
            for k in range(j):
                idx = (i + k) % n
                now[0] += vec[idx][0]
                now[1] += vec[idx][1]
            maxx = max(maxx, now[0]*now[0] + now[1]*now[1])

    print(math.sqrt(maxx))
    return 0

if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
N=int(input())
from cmath import phase
XY=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x: phase(x[0]+x[1]*1j))
XY+=XY
ans=0
for l in range(N):
    a=[0,0]
    for r in range(l,min(2*N,l+N)):
        a[0]+=XY[r][0]
        a[1]+=XY[r][1]
        ans=max(ans,abs(a[0]+a[1]*1j))
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

r_vectors = []
l_vectors = []
py = []
ny = []
for i in range(n):
    x, y = getList()
    if x == 0:
        if y > 0:
            py.append((x, y))
        elif y < 0:
            ny.append((x, y))
        else:
            n -= 1

    elif x > 0:
        r_vectors.append((x, y))
    else:
        l_vectors.append((x, y))




l_vectors.sort(key=lambda v:-v[1]/v[0])
r_vectors.sort(key=lambda v:-v[1]/v[0])


r_vectors = r_vectors + ny

l_vectors = l_vectors + py

vectors = (r_vectors + l_vectors) * 2


ans = 0

for i, start in enumerate(vectors[:n]):
    tx, ty = 0, 0
    for j in range(n):
        
        x, y = vectors[i+j]
        tx += x
        ty += y
        tmp = tx ** 2 + ty ** 2
        
        if ans < tmp:
            ans = tmp


print(math.sqrt(ans))

Solution (Python):
import math
N = int(input())
xy = []
for i in range(N):
  x, y = map(int, input().split())
  xy += [(x, y, math.atan2(y,x))]
xy.sort(key=lambda val:val[2])
x_accum = [0]
y_accum = [0]
for i in range(N):
  x_accum += [x_accum[-1] + xy[i][0]]
  y_accum += [y_accum[-1] + xy[i][1]]
  
ans = 0
for i in range(N+1):
  for j in range(i,N+1):
    ans = max(ans,  math.hypot(x_accum[j]-x_accum[i] ,y_accum[j]-y_accum[i]))
    ans = max(ans,  math.hypot(x_accum[-1] -x_accum[j]+x_accum[i] ,y_accum[-1]-y_accum[j]+y_accum[i]))
print(ans)

Solution (Python):
import math

N = int(input())
A = []
for j in range(N): 
    A.append([int(i) for i in input().split()])
    
for engine in A:
    engine.append(math.degrees(math.atan2(engine[1], engine[0])))

if len(A)==1:
    print(math.sqrt(A[0][0]**2 + A[0][1]**2))
    exit()

A.sort(key=lambda x: x[2])

A = A + A

mx = 0
for i in range(N):
    X = A[i][0]
    Y = A[i][1]
    temp = 0
    for j in range(i+1, i+N):
        if (math.sqrt(X**2 + Y**2)) > mx:
            mx = math.sqrt(X**2 + Y**2)
        X = X + A[j][0]
        Y = Y + A[j][1]
        
        if temp> math.sqrt(X**2 + Y**2):
            break
        temp = (math.sqrt(X**2 + Y**2))
        if (math.sqrt(X**2 + Y**2)) > mx:
            mx = math.sqrt(X**2 + Y**2)

print(mx)

Solution (Python):


import math
import numpy as np

n = int(input())

eng_list = []

for _ in range(n):
    a = np.array(list(map(int, input().split())))
    eng_list.append(a)


angles = []

for i in range(n):
    cos = (np.dot(eng_list[i], np.array([0, 1]))/(np.linalg.norm(eng_list[i])))
    angle = math.degrees(math.acos(cos))
    if eng_list[i][0] < 0:
        angle = 360 - angle
    angles.append(angle)


def hantei(a, b):
    coss = np.dot(a, b)/(np.linalg.norm(a)*np.linalg.norm(b))
    if coss > 1:
        coss = 1.0
    elif coss < -1:
        coss = -1.0
    angg = math.degrees(math.acos(coss))
    if angg < 90.0001:
        return True
    else:
        return False


def distance(a):
    dis = np.linalg.norm(a)
    return dis

pitch = 1 
dist = []

for ikisaki in np.arange(0, 360, pitch):
    dist_location = np.array([0, 0])
    for j in eng_list:
        i = np.array([math.cos(math.radians(ikisaki)), math.sin(math.radians(ikisaki))])
        if hantei(i, j):
            dist_location = dist_location + j
    dist.append(distance(dist_location))

print(max(dist))

Solution (Python):
import cmath
import math
n=int(input())
a=[]
b=[]

for i in range(n):
    x,y=map(int,input().split())
    a.append(complex(x,y))
    b.append(cmath.phase(a[i]))

ma=0

for i in range(n):
    z=a[i]
    c=b[i]-math.pi/2
    d=b[i]+math.pi/2
    l=max([c,-math.pi])
    r=min([d,math.pi])
    
    
    if a[i]!=complex(0,0):
        for j in range(n):
            if j!=i:
                
                if l<=b[j]<=r or (c<=-math.pi and c+2*math.pi<=b[j]<=math.pi) or (d>=math.pi and -math.pi<=b[j]<=d-2*math.pi):
                    z+=a[j]
    ma=max([abs(z),ma])
m=0

for i in range(n):
    if a[i]!=complex(0,0):
        za,zb=complex(0,0),complex(0,0)
        for j in range(n):
            p=cmath.phase(a[j]/a[i])
            if -math.pi<=p<=0:
                za+=a[j]
            if 0<=p<=math.pi:
                zb+=a[j]
        m=max([m,abs(za),abs(zb)])
        if i!=n-1 and a[i]+a[i+1]!=0:
            zc,zd=complex(0,0),complex(0,0)
            for j in range(n):
                p=cmath.phase(a[j]/((a[i]+a[i+1])/2))
                if -math.pi<=p<=0:
                    zc+=a[j]
                if 0<=p<=math.pi:
                    zd+=a[j]
            m=max([m,abs(zc),abs(zd)])

print(max([m,ma]))

Solution (Python):
n = int(input())
pi = 3.141592653589793238462643383279
xy = [list(map(int, input().split())) for _ in range(n)]
import math

atan = [math.atan2(x[0], x[1]) for x in xy]
d = []


def hoge(a):
    ret = 0
    if a % (2*pi) < pi:
        ret = (a % pi)
    elif a % (2*pi)  > pi:
        ret = (a % pi)-pi
    else:
        ret = (a)
    
    return ret  


def seikika(A):
    ret = []
    for a in A:
        ret.append(hoge(a))
    return ret


gyoukaku = atan.copy()
gyoukaku.extend(seikika([a + pi for a in atan]))
M=60
for m in range(M):
    gyoukaku.extend(seikika([a + pi*(2*pi/M*m) for a in atan]))


def dist(xy):
    xx = sum([x[0] for x in xy])
    yy = sum([y[1] for y in xy])
    return (xx ** 2 + yy ** 2) ** 0.5


for g in gyoukaku:
    anglist = seikika([hoge(a - g) for a in atan])
    anglist = seikika(anglist)
    finalxy = []
    for i in range(n):
        if -pi / 2 -0.000001 <= anglist[i] <= pi / 2+0.000001:
            finalxy.append(xy[i])
    d.append(dist(finalxy))

print(max(d))

Solution (Python):


import sys
from math import atan2, degrees, hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -9

N = INT()

degs = []
XY = []
for i in range(N):
    x, y = MAP()
    XY.append((x, y))
    deg = degrees(atan2(y, x))
    if deg < 0:
        
        deg += 360
    degs.append((deg, i))

degs.sort()

degs += [(deg+360, i) for deg, i in degs]

ans = 0
for i in range(N):
    deg, idx = degs[i]
    xsm, ysm = XY[idx]
    ans = max(ans, hypot(xsm, ysm))
    j = i + 1
    
    while degs[j][0] < deg+180:
        _, idx = degs[j]
        x, y = XY[idx]
        xsm += x
        ysm += y
        ans = max(ans, hypot(xsm, ysm))
        j += 1
print(ans)

Solution (Python):
import math

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

X2 = []
for i in range(n):
    if X[i] != [0, 0]:
        X2.append(X[i][:])

X = X2[:]

n = len(X)

if n == 0:
    print(0)
else:

    for i in range(n):
        X[i].append(math.atan2(X[i][1], X[i][0]))

    X.sort(key=lambda x:x[2])

    X += X[:]
    
    ans = 0

    X_sum = [[X[0][0], X[0][1]]]
    for i in range(1, 2*n):
        
        X_sum.append([X_sum[i-1][0] + X[i][0], X_sum[i-1][1] + X[i][1]])

    

    for st in range(0, n):
        for en in range(st+1, st+n+1):
            dis = [0, 0]
            for i in range(st, en):
                
                dis[0] = X_sum[en][0] - X_sum[st][0]
                dis[1] = X_sum[en][1] - X_sum[st][1]
            
            ans = max(ans, (dis[0]**2 + dis[1]**2))


    print(ans ** 0.5)

Solution (Python):
import math
N = int(input())
n = 60

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
import math
N = int(input())
n = 72

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
import math
N = int(input())
n = 100

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
import math
N = int(input())
n = 1000

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * math.cos(theta) + y[j] * math.sin(theta) > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
import math
N = int(input())
n = 1000

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)

Solution (Python):
import sys
from math import atan2, pi

n = int(input())
angles = []
engines = []
pi2 = 2 * pi
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    angle = atan2(y, x)
    angles.append((angle, i))  
    angles.append((angle + pi2, i))  
    engines.append(x + y * 1j)
angles.sort()

r = 0
tmp = 0
total = sum(engines)
ans = 0
for l in range(n):
    angle, i = angles[l]
    limit = angle + pi
    while angles[r][0] < limit:
        tmp += engines[angles[r][1]]
        r += 1
    ans = max(ans, abs(tmp), abs(total - tmp))
    tmp -= engines[i]
print(ans)

Solution (Python):
import sys
from math import atan2, pi

n = int(input())
angles = []
engines = []
pi2 = 2 * pi
for i, line in enumerate(sys.stdin):
    x, y = map(int, line.split())
    angle = atan2(y, x)
    angles.append((angle, i))  
    angles.append((angle + pi2, i))  
    engines.append(x + y * 1j)
angles.sort()

r = 0
tmp = 0
total = sum(engines)
ans = 0
for l in range(n):
    angle, i = angles[l]
    limit = angle + pi - 1e-9
    while angles[r][0] < limit:
        tmp += engines[angles[r][1]]
        r += 1
    ans = max(ans, abs(tmp), abs(total - tmp))
    tmp -= engines[i]
print(ans)

Solution (Python):

n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  X = 0
  Y = 0
  for j in range(i+1,i+n+1):
    x,y = xy[j][1],xy[j][2]
    X += x
    Y += y
    can.append(X**2+Y**2)
if n == 0:
  print(0)
else:
  print(max(can)**.5)

Solution (Python):

n = int(input())
xp = []
xm = []
yp = []
ym = []
for _ in range(n):
  x,y = map(int,input().split())
  if x == 0:
    if y == 0:
      n -= 1
    elif y > 0:
      yp.append([0,x,y])
    else:
      ym.append([0,x,y])
  elif x > 0:
    xp.append([y/x,x,y])
  else:
    xm.append([y/x,x,y])
xp.sort()
xm.sort()
xy = xp + yp + xm + ym
can = []
for i in range(-n,0):
  for j in range(i+1,i+n+1):
    X = 0
    Y = 0
    for k in range(i,j):
      x,y = xy[k][1],xy[k][2]
      X += x
      Y += y
    can.append(X**2+Y**2)
if n == 0:
  print(0)
else:
  print(max(can)**.5)

Solution (Python):
from itertools import combinations
from cmath import phase

N = int(input())
xy = [complex(*map(int, input().split())) for _ in range(N)]
xy.sort(key=phase)
xy += xy
ans = 0
for i, j in combinations(range(N*2+1), 2):
    if j-i<=N:
        ans = max(abs(sum(xy[i:j])), ans)
print(ans)

Solution (Python):
import math
N=int(input())
engines = tuple((complex(*map(int, input().split())) for _ in range(N)))
engines = sorted(list((engine, math.atan2(engine.imag, engine.real))for engine in engines if engine != 0), key=lambda x:x[1])
N=len(engines)
if N == 0:
    print(0)
else:
    total = sum(engine[0] for engine in engines)
    head_index = max(i if engines[i][0].imag < 0 else -1 for i in range(N))
    tail_index = 0
    tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
    maximum = max(abs(tmp), abs(total - tmp))

    while True:
        if head_index < N-1:
            if (engines[head_index+1][0]/engines[tail_index][0]).imag >= 0:
                head_index += 1
            else:
                tail_index += 1
        else:
            if (engines[0][0]/engines[tail_index][0]).imag < 0:
                tail_index += 1
            else:
                break
        tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
        maximum = max(maximum, abs(tmp), abs(total - tmp))

    print(maximum)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

import math

def main(): 
    N = II()
    engines = []
    for _ in range(N):
        x, y = LI()
        angle = math.atan2(y, x)
        engines.append((x,y,angle))

    
    engines.sort(key=lambda x: x[2])

    dist_max = 0
    
    cnt = -1
    for x1, y1, angle1 in engines:
        cnt += 1
        if angle1 <= 0:
            search_criteria = lambda x: True if angle1 <= x < angle1+math.pi else False
        else:
            search_criteria = lambda x: True if (angle1 <= x) or (x < angle1-math.pi) else False
        

        x_sum = 0
        y_sum = 0
        for x, y, angle in engines[cnt:] + engines[:cnt]:
            if search_criteria(angle):
            
                x_sum += x
                y_sum += y
            dist_max = max(dist_max, math.sqrt(x_sum**2 + y_sum**2))
    
    print(dist_max)

main()

Solution (Python):
from itertools import combinations
from cmath import phase
N = int(input())
XY = [complex(*map(int, input().split())) for _ in range(N)]
XY.sort(key=phase)
XY += XY
print(max(abs(sum(XY[i:j])) for i, j in combinations(range(N*2+1), 2) if j-i<=N))

Solution (Python):

N = int(input())

sxy41 = []
sxy23 = []

for i in range(N):
    
    x,y = map(int,input().split())

    if x == 0 and y >= 0:

        s = float("inf")

    elif x == 0 and y < 0:

        s = -1 * float("inf")

    else:

        s = y / x

    if x >= 0:
        sxy41.append([s,x,y])
    else:
        sxy23.append([s,x,y])

sxy41.sort()
sxy23.sort()

sxy = []

for i in sxy41:
    sxy.append(i)
for i in sxy23:
    sxy.append(i)

ans = 0


for i in range(N):

    for j in range(i):

        nowx = 0
        nowy = 0

        for k in range(i-j+1):

            k += j

            nowx += sxy[k][1]
            nowy += sxy[k][2]

        ans = max(ans,(nowx ** 2 + nowy ** 2) ** 0.5)


sxy = []

for i in sxy23:
    sxy.append(i)
for i in sxy41:
    sxy.append(i)


for i in range(N):

    for j in range(i+1):

        nowx = 0
        nowy = 0

        for k in range(i-j+1):

            k += j

            nowx += sxy[k][1]
            nowy += sxy[k][2]

        ans = max(ans,(nowx ** 2 + nowy ** 2) ** 0.5)

print (ans)

Solution (Python):

"""
Created on Sun Sep  1 22:14:11 2019

@author: Yamazaki Kenichi
"""


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

def dfs(c):
    return pow(pow(c[0],2)+pow(c[1],2),1/2)

Case = []
pn=[2];A=100
for L in range(3,A):
    for L2 in pn:
        if L % L2 == 0:
            break
    else:
        pn.append(L)
        if N % L != 0:
            Case.append(L)

ans = 0
res = 0
for i in range(N):
    now = [0,0]
    for j in range(i,i+N):
        j %= N
        tmp = [now[0]+xy[j][0],now[1]+ xy[j][1]]
        if dfs(tmp) > dfs(now):
            now = tmp
    if dfs(now) > res:
        res = dfs(now)
    for c in Case:
        now = [0,0]
        for j in range(i,i+N):
            j = (j*c)%N
            tmp = [now[0]+xy[j][0],now[1]+ xy[j][1]]
            if dfs(tmp) > dfs(now):
                now = tmp
        if dfs(now) > res:
            res = dfs(now)
print(res)