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 math
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((math.atan2(y, x), x, y))

X = sorted(X) * 2
ma = 0
for i in range(N):
    sx = sy = 0
    for j in range(i, i + N):
        sx += X[j][1]; sy += X[j][2]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Solution (Python):
import math
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((math.atan2(x, y), x, y))

X = sorted(X) * 2
m = 0
for i in range(N):
    sx = sy = 0
    for j in range(i, i + N):
        sx += X[j][1]; sy += X[j][2]
        d = sx ** 2 + sy ** 2
        m = max(m, d)

print(m**0.5)

Solution (Python):
import cmath
n=int(input())
l=[None for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    c=complex(a,b)
    l[i]=[cmath.phase(c),c]
l.sort(key=lambda x:x[0])
res=0
for i in range(n):
    c=l[i][1]
    for j in range(1,n):
        cc=c+l[(i+j)%n][1]
        if abs(cc)<abs(c):
            break
        c=cc
    res=max(res,abs(c))
print(res)

Solution (Python):
import math


def main():
    N = int(input())
    P = [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        t = math.atan2(y, x)
        P[i] = (t, x, y)
    P.sort()
    P = P + P
    for i in range(N, 2*N):
        t, x, y = P[i]
        P[i] = (t+math.pi * 2, x, y)
    ans = 0
    for i in range(0, N):
        X, Y = 0, 0
        for j in range(i, N+i):
            _, x, y = P[j]
            X += x
            Y += y
            tmp = math.sqrt(X**2 + Y**2)
            ans = max(tmp, ans)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((math.atan2(x, y), x, y))

X = sorted(X) * 2
ma = 0
for i in range(N):
    sx = sy = 0
    for j in range(i, i + N):
        sx += X[j][1]; sy += X[j][2]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
e=[]
for i in range(n):
    x,y=MI()
    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 bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XY):
    
    SXY = [(math.atan2(y, x), x, y) for x, y in XY]
    SXY.sort()

    ans = 0
    for i in range(N):
        cx = 0
        cy = 0
        for j in range(N):
            _, x, y = SXY[i-j]
            cx += x
            cy += y
            ans = max(ans, cx**2 + cy**2)
    return math.sqrt(ans)


def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print("%.100f" % slv(N, XY))


if __name__ == '__main__':
    main()

Solution (Python):
import cmath

N = int(input())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append(x + y * 1j)

XY.sort(key=lambda x: cmath.phase(x))

ans = 0
for i in range(N):
    for j in range(N):
        if i <= j:
            ans = max(ans, abs(sum(XY[i:j + 1])))
        elif i > j:
            ans = max(ans, abs(sum(XY[:j + 1] + XY[i:])))

print(ans)

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):
import math

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

ans = 0.0
for deg in range(360):
  rad = deg*math.pi/180.0
  u,v = math.cos(rad),math.sin(rad)
  
  x0,y0 = 0.0,0.0
  for n in range(N):
    if 0.0<=u*x[n]+v*y[n]:
      x0 += x[n]
      y0 += y[n]
  ans = max(ans,math.sqrt(x0**2+y0**2))
print(ans)

Solution (Python):
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  x=math.degrees(math.atan2(l[i][1], l[i][0]))
  l[i]=[x,l[i][0],l[i][1]]
l.sort()
L=l+l
ansL=[]
for i in range(n):
  for j in range(i,n+i):
    ctx=0;cty=0
    for k in range(i,j+1):
      ctx+=L[k][1]
      cty+=L[k][2]
    ansL.append((ctx**2+cty**2)**0.5)
print(max(ansL))

Solution (Python):
from math import atan2
def dist(x,y):
    return (x**2+y**2)**(1/2)
n = int(input())
data = []
for i in range(n):
    x,y = map(int,input().split())
    data.append([atan2(y,x),x,y])

data.sort()
data = data + data

ans = 0
for i in range(n):
    for j in range(i+1,n+i+1):
        x, y = 0, 0
        for k in range(i,j):
            x += data[k][1]
            y += data[k][2]
        ans = max(ans,dist(x,y))

print(ans)

Solution (Python):
import math
n = int(input())
xy = []
for i in range(n):
    x, y = [int(item) for item in input().split()]
    if x == 0 and y == 0:
        rad = 0.0
    elif x == 0:
        if y > 0:
            rad = math.pi / 2.0
        elif y < 0:
            rad = -math.pi / 2.0
    else:
        rad = math.atan2(y, x)
    deg = math.degrees(rad)
    xy.append((deg, x, y))

xy.sort()
xy2 = xy[:]
for i, (d, x, y) in enumerate(xy):
    xy2.append((d+360.0, x, y))
    if i == 0:
        xy2.append((d+720.0, x, y))
xy2.sort()

ans = 0.0
for i in range(n):
    for j in range(i+1, i+n+1):
        x = 0.0; y = 0.0
        for k in range(i, j):
            x += xy2[k][1]
            y += xy2[k][2]
        d = math.hypot(x, y)
        ans = max(ans, d)

print(ans)

Solution (Python):
import math
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for x in range(-20,21):
    for y in range(-20,21):
        sx = 0
        sy = 0
        for v in a:
            if v[0]*x+v[1]*y>0:
                sx+=v[0]
                sy+=v[1]
        ans = max(ans,math.sqrt(sx*sx+sy*sy))
print(ans)

Solution (Python):
import math
n=int(input())
XY=[]
for _ in range(n):
    x,y=map(int,input().split())
    if x==y==0:
        continue
    XY.append((x,y))
l=len(XY)
if l:
    XY.sort(key=lambda x: math.atan2(x[1],x[0]))
    ans=0
    XY+=XY
    for i in range(l):
        x,y=0,0
        for j in range(i,i+l):
            x+=XY[j][0]
            y+=XY[j][1]
            ans=max(ans,x**2+y**2)
    print(ans**0.5)
else:
    print(0)

Solution (Python):
import math
import random
from itertools import combinations


def solve_f(n, x_list, y_list, debug=False):
    x_list_4 = [[], [], [], []]
    y_list_4 = [[], [], [], []]
    tan_theta_list_4 = [[], [], [], []]

    
    for i in range(n):
        x, y = x_list[i], y_list[i]
        if x >= 0 and y >= 0:  
            x_list_4[0].append(x)
            y_list_4[0].append(y)
            if x > 0:
                tan_theta_list_4[0].append(y / x)
            elif y > 0:
                tan_theta_list_4[0].append(10000000)
            else:
                tan_theta_list_4[0].append(0)
        elif y >= 0:  
            x_list_4[1].append(x)
            y_list_4[1].append(y)
            tan_theta_list_4[1].append(y / x)
        elif x <= 0:  
            x_list_4[2].append(x)
            y_list_4[2].append(y)
            if x < 0:
                tan_theta_list_4[2].append(y / x)
            else:
                tan_theta_list_4[2].append(10000000)
        else:  
            x_list_4[3].append(x)
            y_list_4[3].append(y)
            tan_theta_list_4[3].append(y / x)

    
    x_list_sorted = []
    y_list_sorted = []
    for i in range(4):
        length = len(x_list_4[i])
        if length > 0:
            x_list_s = [(x_list_4[i][j], tan_theta_list_4[i][j]) for j in range(length)]
            y_list_s = [(y_list_4[i][j], tan_theta_list_4[i][j]) for j in range(length)]
            x_list_s.sort(key=lambda z: z[1])
            y_list_s.sort(key=lambda z: z[1])
            for j in range(length):
                x_list_sorted.append(x_list_s[j][0])
                y_list_sorted.append(y_list_s[j][0])

            if debug:
                print(x_list_s, y_list_s)
    
    res = 0
    x_sum_all = sum(x_list_sorted)
    y_sum_all = sum(y_list_sorted)

    x_list_s_cumsum = [0]
    y_list_s_cumsum = [0]
    x_c = 0
    y_c = 0
    for i in range(n):
        x_c += x_list_sorted[i]
        y_c += y_list_sorted[i]
        x_list_s_cumsum.append(x_c)
        y_list_s_cumsum.append(y_c)

    for i in range(n):
        for j in range(i + 1, n + 1):
            x_sum = x_list_s_cumsum[j] - x_list_s_cumsum[i]
            y_sum = y_list_s_cumsum[j] - y_list_s_cumsum[i]
            r1 = x_sum ** 2 + y_sum ** 2
            r2 = (x_sum_all - x_sum) ** 2 + (y_sum_all - y_sum) ** 2

            res = max(res, r1, r2)

    return math.sqrt(res)


def bruce(n, x_list, y_list):
    items = list(range(n))
    subsets = []
    for i in range(len(items) + 1):
        for c in combinations(items, i):
            subsets.append(list(c))
    res = 0
    for s in subsets:
        x_sum = sum([x_list[i] for i in s])
        y_sum = sum([y_list[i] for i in s])
        r = x_sum ** 2 + y_sum ** 2
        res = max(res, r)

    return math.sqrt(res)


def test(n, trial=1000):
    for t in range(trial):
        x_list = []
        y_list = []
        for i in range(n):
            x_list.append(random.choice(range(-9, 10)))
            y_list.append(random.choice(range(-9, 10)))
        if bruce(n, x_list, y_list) != solve_f(n, x_list, y_list):
            break
    if t != trial - 1:
        print(n, x_list, y_list)
        _ = solve_f(n, x_list, y_list, True)


def main():
    n = int(input())
    x_list = [0] * n
    y_list = [0] * n
    for m in range(n):
        x, y = map(int, input().split())
        x_list[m] = x
        y_list[m] = y
    print(solve_f(n, x_list, y_list))


if __name__ == "__main__":
    
    main()

Solution (Python):
import math
n=int(input())
def f(x,y):
  return math.atan2(y,x)
  
XY=[]
for i in range(n):
  x,y=map(int,input().split())
  XY.append((x,y,f(x,y)))
XY.sort(key=lambda x:x[2])

def dis(x,y):
  return (x**2+y**2)**0.5
ans=0
for i in range(n):
  for j in range(1,n+1):
    x,y=0,0
    if i+j<=n:
      for k in range(i,i+j):
        x+=XY[k][0]
        y+=XY[k][1]
      ans=max(ans,dis(x,y))
    else:
      for k in range(i,n):
        x+=XY[k][0]
        y+=XY[k][1]
      for k in range(j-(n-i)):
        x+=XY[k][0]
        y+=XY[k][1]
      ans=max(ans,dis(x,y))
print(ans)

Solution (Python):
from math import sin,cos,pi
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]

R = []
e = 1e-5
for n in range(10**5+1):
    R.append([cos(2*pi*n/10**5),sin(2*pi*n/10**5)])

ans = 0
for Rx,Ry in R:
    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())
info=[list(map(int,input().split())) for i in range(n)]
ans=0

for i in range(n):
  x=info[i][0]
  y=info[i][1]
  info[i].append(x)
  info[i].append(y)
  info[i][0]=math.atan2(y,x)
  info[i][1]=(x**2+y**2)**0.5
info.sort()

allx=0
ally=0

for i in range(n):
  allx+=info[i][2]
  ally+=info[i][3]

for i in range(n):
  for j in range(i+1,n+1):
    ax=0
    ay=0
    for k in range(i,j):
      ax+=info[k][2]
      ay+=info[k][3]
    ans=max(ans,(ax**2+ay**2)**0.5,((allx-ax)**2+(ally-ay)**2)**0.5)
  
print(ans)

Solution (Python):
from math import atan2, sqrt
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
P.sort(key=lambda p: atan2(p[1], p[0]))

ans = 0
for i in range(N):
    cx = cy = 0
    for j in range(N):
        x, y = P[(i+j) % N]
        cx += x; cy += y
        ans = max(ans, cx**2 + cy**2)
print("%.16f" % sqrt(ans))

Solution (Python):
n = int(input())
xy1 = []
xy2 = []
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        continue
    cos = x / (x ** 2 + y ** 2) ** 0.5
    sin = y / (x ** 2 + y ** 2) ** 0.5
    if sin >= 0:
        xy1.append([x, y, cos])
    else:
        xy2.append([x, y, cos])
xy1.sort(key = lambda x: x[2], reverse = True)
xy2.sort(key = lambda x: x[2])
xy = xy1 + xy2
xy = xy + xy
max_vector = 0
for i in range(len(xy) // 2):
    for j in range(i, i + len(xy) // 2):
        x, y = 0, 0
        for k in range(i, j + 1):
            x += xy[k][0]
            y += xy[k][1]
        max_vector = max(max_vector, (x ** 2 + y ** 2) ** 0.5)
print(max_vector)

Solution (Python):
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
    
R = []
e = 1e-5
for x,y in xy:
    R.append([x,y])
    R.append([-x,-y])
    R.append([y,-x])
    R.append([-y,x])
    R.append([x+e,y+e])
    R.append([-x-e,-y-e])
    R.append([y+e,-x-e])
    R.append([-y-e,x+e])
    R.append([x+e,y-e])
    R.append([-x-e,-y+e])
    R.append([y-e,-x-e])
    R.append([-y+e,x+e])
    R.append([x-e,y+e])
    R.append([-x+e,-y-e])
    R.append([y+e,-x+e])
    R.append([-y-e,x-e])
    R.append([x-e,y-e])
    R.append([-x+e,-y+e])
    R.append([y-e,-x+e])
    R.append([-y+e,x-e])

ans = 0
for Rx,Ry in R:
    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())
ans = 0
l = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(1001):
  th = 2*i*math.pi/1000
  thx = math.cos(th)
  thy = math.sin(th)
  cx,cy = 0,0
  for dx,dy in l:
    if thx*dx+thy*dy > 0:
      cx += dx
      cy += dy
  ans = max(ans,cx**2+cy**2)
print(ans**.5)

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

import numpy as np


def check(engines, theta):
    x, y = 0, 0
    cur = 0
    best = 0
    for dx, dy in engines:
        nx = x + dx
        ny = y + dy
        r = (nx ** 2 + ny ** 2) ** 0.5
        phi = atan2(ny, nx)
        new = r * cos(phi - theta)

        if cur < new:
            x, y = nx, ny
            cur = new
            best = r
    return best


n = int(input())
engines = []
for line in sys.stdin:
    x, y = map(int, line.split())
    engines.append((x, y))

ans = 0
for theta in np.linspace(0, 2 * pi, 10000, False):
    ans = max(ans, check(engines, theta))
print(ans)

Solution (Python):
from math import atan2, sqrt
N = int(input())
E = []
for _ in range(N):
    x, y = map(int, input().split())
    d = atan2(y, x)
    E.append((d, x, y))

E.sort()

dp = [[(0, 0)] * N for _ in range(N)]

ans = 0
for i in range(N):
    _, xi, yi = E[i]
    dist = xi ** 2 + yi ** 2
    ans = max(ans, dist)
    dp[i][i] = (xi, yi)
    for j in range(i+1,i+N):
        j %= N
        _, xj, yj = E[j]
        dp[i][j] = (dp[i][j-1][0] + xj, dp[i][j-1][1] + yj)
        dist = dp[i][j][0] ** 2 + dp[i][j][1] ** 2
        ans = max(ans, dist)

print(sqrt(ans))

Solution (Python):
import sys
import math
input = sys.stdin.readline
N=int(input())
xys = []
for _ in range(N):
    xys.append(list(map(int, input().split())))

def z(mx,my):
    rx, ry = 0,0
    for x, y in xys:
        if x*mx + y*my > 0:
            rx, ry = (rx + x), (ry + y)
    return pow(pow(rx, 2) + pow(ry, 2), 1/2)

M = 1000
r = 0
for i in range(M):
    k = 2*(i/M)*math.pi
    r = max(r, z(math.cos(k), math.sin(k)))
print(r)

Solution (Python):
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

from math import atan2, pi
def solve(N, A):
    A.sort(key = lambda (x, y): atan2(y, x))
    A = A + A
    P = [0]
    for x, y in A:
        P.append(P[-1] + (x + y * 1j))

    ans = 0
    for i in xrange(N):
        for j in xrange(i, i+N):
            ans = max(ans, abs(P[j+1] - P[i]))
    return ans

                
N=rri()
A=[rrm() for _ in xrange(N)]
print solve(N, A)

Solution (Python):
from collections import defaultdict, deque, Counter
import sys
import heapq
import math



sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7


def norm(theta):
    if theta > math.pi:
        return theta - 2 * math.pi
    if theta < -math.pi:
        return theta + 2 * math.pi


def solve(state, xy):
    xx, yy = 0, 0
    for i in state:
        x, y = xy[i]
        xx += x
        yy += y
    return math.sqrt(xx * xx + yy * yy)


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

    ttt = []
    ts = []
    for i, (x, y) in enumerate(xy):
        theta = math.atan2(y, x)
        m1 = theta - math.pi / 2
        m2 = theta + math.pi / 2
        b = [(m1, m2)]
        if m1 < -math.pi:
            b = [
                (-math.pi, m2),
                (m1 + 2 * math.pi, math.pi)
            ]
        elif m2 > math.pi:
            b = [
                (-math.pi, m2 - 2 * math.pi),
                (m1, math.pi)
            ]
        ts.append(b)
        
        for xx, yy in b:
            ttt.append((xx, i, "enter"))
            ttt.append((yy, i, "leave"))

    result = 0
    state = set()
    for p, i, typ in sorted(ttt, key=lambda a: a[0]):
        
        if typ == "enter":
            state.add(i)
        else:
            state.remove(i)

        score = solve(state, xy)
        
        result = max(result, score)
        
    print(result)


















if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

from math import atan2

pts = []
for x, y in xy:
    if x == 0 and y == 0:
        continue
    else:
        pts.append((atan2(y, x), x, y))

pts.sort()

cum_xy = [(0, 0)]
for a, x, y in pts:
    pv_x, pv_y = cum_xy[-1]
    cum_xy.append((pv_x + x, pv_y + y))

ans2 = 0

for i in range(len(cum_xy)):
    for j in range(i, len(cum_xy)):
        length = (cum_xy[j][0] - cum_xy[i][0]) ** 2 + (cum_xy[j][1] - cum_xy[i][1]) ** 2
        if length > ans2:
            ans2 = length

        length = (cum_xy[j][0] - cum_xy[i][0] - cum_xy[-1][0]) ** 2 + (
            cum_xy[j][1] - cum_xy[i][1] - cum_xy[-1][1]
        ) ** 2
        if length > ans2:
            ans2 = length

print(ans2 ** 0.5)

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(1000):
    th = 2*np.pi*m/1000
    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):
N = int(input())

v_list = []
for _ in range(N):
	v_list.append(tuple(map(int, input().strip().split())))

import math

v_list2 = []
for x, y in v_list:
	r = math.atan2(x, y)
	v_list2.append((r, x, y))

v_list2.sort()

max_dist = 0
for i in range(N):
	for w in range(1, N + 1):
		x = 0
		y = 0
		for j in range(w):
			r, dx, dy = v_list2[(i + j) % N]
			x += dx
			y += dy
		dist = x * x + y * y
		if dist > max_dist:
			max_dist = dist

print(math.sqrt(max_dist))

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for _ in [0]*n]
l1=[]
l2=[]
l3=[]
l4=[]
for i in range(n):
    if l[i][0]==0:
        if l[i][1]>0:
            l1.append(l[i])
        else:
            l3.append(l[i])
    elif l[i][0]<0:
        l2.append(l[i])
    else:
        l4.append(l[i])
L=l1+sorted(l2,key=lambda x:x[1]/x[0])+l3+sorted(l4,key=lambda x:x[1]/x[0])
L=[[0,0]]+L*2

for i in range(1,n*2+1):
    L[i]=[L[i-1][0]+L[i][0],L[i-1][1]+L[i][1]]
ans=0

for i in range(n+1):
    for j in range(i,i+n+1):
        ans=max(ans,(L[j][0]-L[i][0])**2+(L[j][1]-L[i][1])**2)
print(ans**.5)

Solution (Python):
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

import math

xy.sort(key = lambda x: math.atan2(x[1], x[0]))
atanxy = [math.atan2(yi, xi) for xi, yi in xy]
    



ans2 = 0



















for src in range(N):
    x_tmp, y_tmp = xy[src]
    if ans2 < (x_tmp ** 2 + y_tmp ** 2):
        ans2 = (x_tmp ** 2 + y_tmp ** 2)
    for j in range(1, N):
        dst = (src + j) % N
        x_tmp += xy[dst][0]
        y_tmp += xy[dst][1]
        
        if ans2 < (x_tmp ** 2 + y_tmp ** 2):
            ans2 = (x_tmp ** 2 + y_tmp ** 2)

print(math.sqrt(ans2))

Solution (Python):
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    s = 1 if x < 0 else 0
    r = y/(x+10**-100)
    X.append((s, r, x, y))

X = sorted(X) * 2
ma = 0
for i in range(N):
    sx, sy = 0, 0
    for j in range(i, i + N):
        sx += X[j][2]
        sy += X[j][3]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

decimal.getcontext().prec = 50

N = input()
x = []
y = []
for i in range(N):
    x_, y_ = map(int, raw_input().split())
    x += [decimal.Decimal(x_)]
    y += [decimal.Decimal(y_)]

ans = 0

for i in range(N):
    for j in range(N - 1):
        if math.atan2(x[j], y[j]) > math.atan2(x[j + 1], y[j + 1]):
            x[j], x[j + 1] = x[j + 1], x[j]
            y[j], y[j + 1] = y[j + 1], y[j]
for i in range(N):
    for j in range(N):
        X = decimal.Decimal(0)
        Y = decimal.Decimal(0)
        for k in range(N):
            if i <= j and i <= k <= j:
                X += x[k]
                Y += y[k]
            elif j < i and not j < k < i:
                X += x[k]
                Y += y[k]
        ans = max(ans, X * X + Y * Y)

print math.sqrt(ans)

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

decimal.getcontext().prec = 50

N = input()
x = []
y = []
for i in range(N):
    x_, y_ = map(int, raw_input().split())
    x += [decimal.Decimal(x_)]
    y += [decimal.Decimal(y_)]

ans = 0

for i in range(N):
    for j in range(N - 1):
        if math.atan2(x[j], y[j]) > math.atan2(x[j + 1], y[j + 1]):
            x[j], x[j + 1] = x[j + 1], x[j]
            y[j], y[j + 1] = y[j + 1], y[j]
for i in range(N):
    for j in range(N):
        X = decimal.Decimal(0)
        Y = decimal.Decimal(0)
        for k in range(N):
            if i <= j and i <= k <= j:
                X += x[k]
                Y += y[k]
            elif j < i and not j < k < i:
                X += x[k]
                Y += y[k]
        ans = max(ans, X * X + Y * Y)

L = decimal.Decimal(0)
R = decimal.Decimal(INF)

for loop in range(1000):
    mid = (L + R) / 2
    if mid * mid <= ans:
        L = mid
    else:
        R = mid
print L

Solution (Python):
import math
from itertools import accumulate
N = int(input())
X = []
Y = []
for _ in range(N):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)


arr = []
for x, y in zip(X, Y):
  arr.append((math.atan2(y, x), x, y))
arr.sort()
accX = list(accumulate([a[1] for a in arr]))
accY = list(accumulate([a[2] for a in arr]))

ans = float('-inf')
for f in range(N):
  for t in range(N):
    if f <= t:
      tmpX = accX[t] - (accX[f-1] if f > 0 else 0)
      tmpY = accY[t] - (accY[f-1] if f > 0 else 0)
      tmp = tmpX**2 + tmpY**2
      ans = ans if ans > tmp else tmp
    else:
      tmpX = accX[N-1] - (accX[f-1] if f > 0 else 0) + accX[t]
      tmpY = accY[N-1] - (accY[f-1] if f > 0 else 0) + accY[t]
      tmp = tmpX**2 + tmpY**2
      ans = ans if ans > tmp else tmp
print(math.sqrt(ans))

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline



from math import atan2, pi
from bisect import *

n = int(input())

ans = 0
txy = []
for _ in range(n):
    x,y = [int(i) for i in readline().split()]
    ans = max(ans,x*x+y*y)
    txy.append((atan2(y,x),x,y))
    txy.append((atan2(y,x)+2*pi,x,y))

txy.sort()


N= 100000
a = 2*pi/N

id1 = id2 = 0
for i in range(N):
    r = i*a
    
    nid1 = bisect(txy,(r,0,0))
    nid2 = bisect(txy,(r+pi,0,0))

    if id1 == nid1 and id2 == nid2: continue
    id1,id2 = nid1,nid2
    
    rx = ry = 0
    for t,x,y in txy[id1:id2]:
        rx += x
        ry += y
    
    ans = max(ans,rx*rx+ry*ry)




print(ans**0.5)

Solution (Python):
from math import radians, sin, cos, sqrt
EPS = 1e-10

n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for theta in range(0, 3600):
	e = (cos(radians(theta/10)), sin(radians(theta/10)))
	resx, resy = 0, 0
	for x, y in d:
		if x*e[0] + y*e[1] >= EPS:
			resx += x
			resy += y
	ans = max(ans, sqrt(resx**2 + resy**2))
print(ans)

Solution (Python):
import math
pi = math.atan(1) * 4
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    if x == y == 0: continue
    if x == 0:
        r = pi/2 if y > 0 else -pi/2
    else:
        r = math.atan(y/x)
        if x < 0: r += pi
    X.append((x, y, r))

X = sorted(X, key = lambda x: x[2]) * 2
M = len(X)
ma = 0
for i in range(M):
    sx, sy = 0, 0
    for j in range(i+1, min(i+M//2+1, M)):
        sx += X[j][0]
        sy += X[j][1]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Solution (Python):

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])
def get_convex_hull(points):
    n = len(points)
    points.sort()
    size_convex_hull = 0
    ch = []
    for i in range(n):
        while size_convex_hull > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    t = size_convex_hull
    for i in range(n-2, -1, -1):
        while size_convex_hull > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    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)