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

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():
    n = I()
    p = LIR(n)
    p.sort(key = lambda x : (x[0] < 0, x[1]/(x[0]+1e-9)))
    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):

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():
    n = I()
    p = LIR(n)
    p.sort(key = lambda x : (x[0] < 0, x[1]/x[0] if x[0] != 0 else x[1]*1e9))
    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):

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():
    n = I()
    p = LIR(n)
    p.sort(key = lambda x : (x[0] >= 0, x[1]/x[0] if x[0] != 0 else x[1]*1e9))
    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 numpy as np
n = int(input())
xy = np.array([list(map(int, input().split())) for _ in range(n)]).T
ans = 0
L = np.angle(xy[0]+xy[1]*1j)
A = sorted([[j, xy[0][i], xy[1][i]] for i, j in enumerate(L)])
A = [i[1:] for i in A]
A = np.array(A*2)
for i in range(n):
  for j in range(i+1, i+n+1):
    S = A[i:j]
    t = S.sum(axis=0)
    ans = max(ans, np.hypot(*t))
print(ans)

Solution (Python):
import math
N=int(input())
data=[]
p=math.pi
e=10**(-9)
for i in range(N):
    x,y=map(int,input().split())
    data.append([math.atan2(y,x),x,y])
    data.append([math.atan2(y,x)+2*p,x,y])
data.sort()
ans=0
for left in range(N):
    x_sum=0
    y_sum=0
    right=left
    while data[right][0]-data[left][0]<=p-e:
        x_sum+=data[right][1]
        y_sum+=data[right][2]
        ans=max(ans,x_sum**2+y_sum**2)
        right+=1
print(ans**0.5)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from cmath import phase
def resolve():
    n=int(input())
    C=[None]*n
    for i in range(n):
        x,y=map(int,input().split())
        C[i]=x+y*1j

    C.sort(phase)
    C*=2

    ans=0
    for i in range(n):
        for j in range(i+1,n+1):
            ans=max(ans,abs(sum(C[i:j])))
            ans=max(ans,abs(sum(C[j:n+i])))

    print(ans)
resolve()

Solution (Python):
L = 10**10

N = int(input())
x, y = zip(*(map(int, input().split()) for _ in range(N)))

result = 0
for i in range(N):
    for b in [-1, 1]:
        for s, t in [(y[i], -x[i]), (-y[i], x[i])]:
            s, t = L * s - b * t, b * s + L * t
            X = 0
            Y = 0
            for j in range(N):
                if x[j] * s + y[j] * t > 0:
                    X += x[j]
                    Y += y[j]
            result = max(result, (X**2 + Y**2)**0.5)
print(result)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
import time


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


def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return


def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return


def D():
    n = II()
    print(n * (n - 1) // 2)
    return


def E():
    start = time.time()
    n = II()
    a = LIR_(n)
    ans = 0
    tern = [0] * n
    while 1:
        ans += 1
        f = True
        c = defaultdict(int)
        for i in range(n):
            if c[i]:
                continue
            if tern[i] == n - 1:
                continue
            rival = a[i][tern[i]]
            if c[rival]:
                continue
            if tern[rival] == n - 1:
                continue
            if a[rival][tern[rival]] == i:
                c[i] += 1
                c[rival] += 1
                tern[rival] += 1
                tern[i] += 1
                f = False
        if time.time() - start >= 1:
            print(n * (n - 1) // 2)
            return
        if f:
            if tern == [n - 1] * n:
                print(ans-1)
                return
            else:
                print(-1)
                return
    return












def F():
    n = II()
    lis = []
    for _ in range(n):
        x, y = LI()
        arg = math.atan2(y, x) / math.pi * 180
        lis.append((arg, x, y))
        lis.append((arg + 360, x, y))
    lis.sort()
    i = 0
    k = 0
    tmpx = 0
    tmpy = 0
    ans = 0
    while i < n:
        arg, x, y = lis[i]
        while k < 2 * n:
            karg, kx, ky = lis[k]
            if karg < arg + 180:
                tmpx += kx
                tmpy += ky
                ans = max(ans, sqrt(tmpx ** 2 + tmpy ** 2))
                k += 1
            else:
                tmpx -= x
                tmpy -= y
                ans = max(ans, sqrt(tmpx ** 2 + tmpy ** 2))
                break
        i += 1
    print(ans)
    return


if __name__ == '__main__':
    F()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
import time


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


def B():
    a, b = LI()
    ans = 0
    b -= 1
    while b > 0:
        b -= a - 1
        ans += 1
    print(ans)

    return


def C():
    n = II()
    h = LI()
    i = 0
    ans = 0
    while i < n:
        down = i+1
        while down < n:
            if h[down - 1] >= h[down]:
                down += 1
            else:
                break
        ans = max(ans, down - i - 1)
        i = down
    print(ans)
    return


def D():
    n = II()
    print(n * (n - 1) // 2)
    return


def E():
    start = time.time()
    n = II()
    a = LIR_(n)
    ans = 0
    tern = [0] * n
    while 1:
        ans += 1
        f = True
        c = defaultdict(int)
        for i in range(n):
            if c[i]:
                continue
            if tern[i] == n - 1:
                continue
            rival = a[i][tern[i]]
            if c[rival]:
                continue
            if tern[rival] == n - 1:
                continue
            if a[rival][tern[rival]] == i:
                c[i] += 1
                c[rival] += 1
                tern[rival] += 1
                tern[i] += 1
                f = False
        if time.time() - start >= 1:
            print(n * (n - 1) // 2)
            return
        if f:
            if tern == [n - 1] * n:
                print(ans-1)
                return
            else:
                print(-1)
                return
    return












def F():
    n = II()
    lis = []
    for _ in range(n):
        x, y = LI()
        arg = math.atan2(y, x) / math.pi * 180
        lis.append((arg, x, y))
        lis.append((arg + 360, x, y))
    lis.sort()
    ans = 0
    for i in range(n):
        tmpx = 0
        tmpy = 0
        for k in range(i, i + n):
            _, x, y = lis[k]
            tmpx += x
            tmpy += y
            ans = max(ans, sqrt(tmpx ** 2 + tmpy ** 2))
    print(ans)
    return


if __name__ == '__main__':
    F()

Solution (Python):
from math import *

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

data.sort()
ret = 0
for i in range(N):
    x = data[i][1]
    y = data[i][2]
    ret = max(ret, sqrt(x**2 + y**2))

for i in range(N):
    for j in range(N):
        if i < j and data[j][0] - data[i][0] < pi:
            x = 0
            y = 0
            for k in range(i, j+1):
                x += data[k][1]
                y += data[k][2]
            ret = max(ret, sqrt(x**2 + y**2))
        elif i > j and data[i][0] - data[j][0] >= pi:
            x = 0
            y = 0
            for k in range(i, N):
                x += data[k][1]
                y += data[k][2]
            for k in range(j+1):
                x += data[k][1]
                y += data[k][2]
            ret = max(ret, sqrt(x**2 + y**2))

print(ret)

Solution (Python):
import sys
readline = sys.stdin.readline
from math import atan2, hypot
from itertools import accumulate
N = int(readline())
XY = [tuple(map(int, readline().split())) for _ in range(N)]
XY.sort(key = lambda x: atan2(*x))
X, Y = list(map(list, zip(*XY)))
X, Y = list(accumulate(X*2)), list(accumulate(Y*2))
ans = 0
for i in range(N):
    for j in range(1, N+1):
        ans = max(ans, hypot(X[i+j]-X[i], Y[i+j]-Y[i]))
print(ans)

Solution (Python):
import math
from operator import itemgetter


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

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

info = sorted(info, key = itemgetter(2))
info = info + info
ans = 0

for i in range(n):
    tmp = [0, 0]
    for j in range(n):
        tmp[0] += info[i+j][0]
        tmp[1] += info[i+j][1]
        tmp_ans = tmp[0]**2 + tmp[1]**2
        ans = max(tmp_ans, ans)

print(ans**0.5)

Solution (Python):
import sys
from itertools import accumulate, combinations
from math import atan2
read = sys.stdin.read

N, *xy = map(int, read().split())
xy = sorted(zip(*[iter(xy)] * 2), key=lambda x: atan2(x[1], x[0]))
xy = [(0, 0)] + xy

xy *= 2
xy = list(zip(*map(list, map(accumulate, zip(*xy)))))
answer = 0

for i, j in combinations(range(2 * N + 2), 2):
    if j - i <= N:
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        candidate = (x1 - x2) ** 2 + (y1 - y2) ** 2
        if candidate > answer:
            answer = candidate

print(answer ** 0.5)

Solution (Python):
import sys
from itertools import accumulate, combinations
from math import atan2
read = sys.stdin.read

N, *xy = map(int, read().split())
xy = sorted(zip(*[iter(xy)] * 2), key=lambda x: atan2(x[1], x[0]))
xy = [(0, 0)] + xy

xy *= 2
xy = list(zip(*map(list, map(accumulate, zip(*xy)))))
answer = 0

for n in range(N + 1):
    for i, j in combinations(range(n, n + N + 1), 2):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        candidate = (x1 - x2) ** 2 + (y1 - y2) ** 2
        if candidate > answer:
            answer = candidate

print(answer ** 0.5)

Solution (Python):
N = int(input())
points = []
for i in range(N):
    x, y = map(int, input().split())
    if (x, y) == (0, 0): N -= 1; continue
    points.append((x,y))

if not points:
    print(0)
    quit()
    
PI = 3.14

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

def calc(points):
    
    l = 0
    h = 1

    xsum = points[0][0]
    ysum = points[0][1]

    highest = xsum ** 2 + ysum ** 2
    while h < len(points):
        nx, ny = xsum - points[l][0], ysum - points[l][1]
        if (not l >= h) and nx ** 2 + ny ** 2 > xsum ** 2 + ysum ** 2 or h - l >= N:
            xsum, ysum = nx, ny
            l += 1
        else:
            xsum += points[h][0]
            ysum += points[h][1]
            h += 1
        highest = max(highest, xsum ** 2 + ysum ** 2)
    return highest

def calc2(points):
    hi = 0
    
    for s in range(N):
        for j in range(1,N+1):
            xt = yt = 0
            for x in range(j):
                xt += points[s+x][0]
                yt += points[s+x][1]
            hi = max(hi, xt ** 2 + yt ** 2)

    return hi ** 0.5

print(calc2(points + points))

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

D = []
import math

for i in range(N):
  x, y = xy[i]
  t = math.atan2(y, x)
  t = math.degrees(t)
  if t < 0:
    t += 360
  D.append([t, x, y])

import copy
D.sort()
D = D + copy.deepcopy(D)
for i in range(N, N + N):
  D[i][0] += 360

ans = 0
for i in range(N):
  x, y = 0, 0
  d = D[i][0]
  for j in range(i, i + N):
    t = D[j][0]
    if t - d > 180:
      break
    x += D[j][1]
    y += D[j][2]
    l = (x ** 2 + y ** 2) ** (1 / 2)
    ans = max(ans, l)

print(ans)

Solution (Python):
import math

N=int(input())
e=[]
for i in range(N):
    x,y=map(int,input().split())
    t=math.atan2(y,x)
    e.append((x,y,t));e.append((x,y,t+2*math.pi))

e.sort(key=lambda z:z[2])


sqans=0
for i in range(N):
    dx=e[i][0];dy=e[i][1]
    sqans=max(sqans,dx**2+dy**2)
    for j in range(i+1,i+N):
        dx+=e[j][0];dy+=e[j][1]
        sqans=max(sqans,dx**2+dy**2)
ans=math.sqrt(sqans)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    C=[0]*n
    for i in range(n):
        x,y=map(int,input().split())
        C[i]=x+y*1j

    from cmath import phase
    C.sort(phase)
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+C[i]

    ans=-INF
    for j in range(n+1):
        for i in range(j):
            ans=max(ans,abs(S[j]-S[i]))
            ans=max(ans,abs(S[-1]-(S[j]-S[i])))
    print(ans)
resolve()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
xy = []
for x, y in LIR(n):
    xy += [(atan2(y, x), x, y)]


xy.sort()
xy += xy

cs = [(0, 0)]
for _, x, y in xy:
    cs += [(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, x2 = cs[i][0], cs[j][0]
        y1, y2 = cs[i][1], cs[j][1]
        ans = max(ans, (x2 - x1) ** 2 + (y2 - y1) ** 2)


print(ans ** 0.5)

Solution (Python):
from math import atan2, pi, sqrt
from operator import itemgetter



n = int(input())
p = []
xa = ya = 0
for i in range(n):
    x, y = map(int, input().split())
    angle = atan2(y, x)
    p.append((x, y, angle))
    p.append((x, y, angle + 2 * pi))
    xa += x
    ya += y

p.sort(key=itemgetter(2))

r = 0
ans = 0
xs = ys = 0
for l in range(n):
    while p[r][2] < p[l][2] + pi:
        xs += p[r][0]
        ys += p[r][1]
        r += 1

    ans = max(ans, sqrt(xs**2 + ys**2), sqrt((xa - xs)**2 + (ya - ys)**2))

    xs -= p[l][0]
    ys -= p[l][1]

print(ans)

Solution (Python):
from math import atan2, pi, sqrt
from operator import itemgetter
import sys
input = sys.stdin.readline

n = int(input())
p = []
xa = ya = 0
for i in range(n):
    x, y = map(int, input().split())
    angle = atan2(y, x)
    p.append((x, y, angle))
    p.append((x, y, angle + 2 * pi))
    xa += x
    ya += y

p.sort(key=itemgetter(2))

r = 0
ans = 0
xs = ys = 0
for l in range(n):
    while p[r][2] < p[l][2] + pi:
        xs += p[r][0]
        ys += p[r][1]
        r += 1

    ans = max(ans, sqrt(xs**2 + ys**2), sqrt((xa - xs)**2 + (ya - ys)**2))

    xs -= p[l][0]
    ys -= p[l][1]

print(ans)

Solution (Python):
from math import atan2, pi, sqrt
n = int(input())
p = []
xa = ya = 0
for i in range(n):
    x, y = map(int, input().split())
    angle = atan2(y, x)
    p.append((x, y, angle))
    p.append((x, y, angle + 2 * pi))
    xa += x
    ya += y

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

r = 0
ans = 0
xs = ys = 0
for l in range(n):
    while p[r][2] < p[l][2] + pi:
        xs += p[r][0]
        ys += p[r][1]
        r += 1

    ans = max(ans, sqrt(xs**2 + ys**2), sqrt((xa - xs)**2 + (ya - ys)**2))

    xs -= p[l][0]
    ys -= p[l][1]

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = []
for i in range(n):
    x, y = LI()
    L += [(atan2(y, x), x, y)]


L.sort()
L += L
cs = [(0, 0)]
for _, x, y in L:
    cs += [(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, x2 = cs[i][0], cs[j][0]
        y1, y2 = cs[i][1], cs[j][1]
        ans = max(ans, (x2 - x1) ** 2 + (y2 - y1) ** 2)


print(ans ** 0.5)