Under construction

Still being built. Things may change

Walking Route

Interview

Time limit1sMemory limit128 MB

Summary
Given N vectors forming a walking route, output the total displacement and the minimum distance from the start after removing exactly one segment.
Level

Easy3 of 10

Topics
Array, Math, Brute force
Solved
No attempts yet

Problem

A navigation device suggests one walking route. The route consists of several line segments, and each segment is represented by two integers (X, Y). This pair is a vector that describes the direction and distance of that segment.

For instance, the route in the left figure below consists of four segments. The first segment is (-1, 1), the second is (1, 1), the third is (1, 0), and the fourth is (0, -2). After following the whole route, the final position is 1 meter east of the starting position.

To avoid ending the walk too far from the start, exactly one segment will be removed from the route. After removing one segment, the remaining segments are still followed in their original order, and the distance between the starting position and the final position should be as small as possible.

In the route shown in the figure, removing the third segment makes the final position exactly match the starting position, as in the right figure.

Given the suggested walking route, compute the final position when the whole route is used as given, and the minimum possible distance between the starting position and the final position after removing exactly one segment.

Input

The first line contains the number of segments N. (1 < N <= 30)

Each of the next N lines contains two integers X and Y describing one segment. (-1000 <= X, Y <= 1000)

Output

On the first line, print the final position after following the whole walking route. The starting position is (0, 0), and the final position must be printed in the form x y.

On the second line, print the minimum possible distance between the starting position and the final position after removing exactly one segment, rounded to two digits after the decimal point.

Examples3

  1. Example 1

    Input
    4
    -1 1
    1 1
    1 0
    0 -2
    
    Expected output
    1 0
    0.00
    
  2. Example 2

    Input
    3
    0 1
    1 0
    -1 -1
    
    Expected output
    0 0
    1.00
    
  3. Example 3

    Input
    4
    0 5
    5 0
    0 -5
    -5 0
    
    Expected output
    0 0
    5.00