Under construction

Still being built. Things may change

Interstellar Travel

Time limit5sMemory limit512 MB

Summary
Given n angular intervals where each star contributes t - s*dist(a,b), find the launch angle b maximizing the sum of contributions.
Level

Hard8 of 10

Topics
Geometry, Math, Brute force, Sorting
Solved
No attempts yet

Problem

You are planning to travel through interstellar space in the hope of finding habitable planets. You have already identified n stars that can recharge your spaceship through its solar panels. The only work left is to decide the orientation of the spaceship that maximizes the distance it can travel.

Space is modeled as a 2D plane, with the Earth at the origin. The spaceship can be launched from the Earth in a straight line, in any direction. A star can provide enough energy to travel a certain distance if the spaceship is launched at a certain angle with the X-axis. If the angle is not perfectly aligned, the spaceship gets less energy.

Each star has a distance t that the spaceship can travel if launched at an angle a with the X-axis, and a multiplier s that indicates how the distance decays as angles diverge from a. If the launch direction makes an angle of b with the X-axis, the spaceship gets enough energy to travel a distance of:

max(0, t - s · dist[a, b])

where dist[a, b] is the minimum non-negative radians needed to go between angles a and b. The total distance the spaceship can travel is the sum of the distances that each star contributes.

Find the maximum distance the starship can travel.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105), the number of stars.

Each of the next n lines contains three space-separated real numbers

t (0.0 < t ≤ 1000.0) s (0.0 ≤ s ≤ 100.0) a (0.0 ≤ a < 2π)

where t is the greatest distance that star's energy can support, s is that star's decay multiplier, and a is the best angle for achieving the greatest distance from that star's energy.

Output

Output a single real number, the maximum distance that the spacecraft can travel. Your answer must be accurate to within 10-6 absolute or relative error.

Examples2

  1. Example 1

    Input
    2
    100 1 1
    100 1 1.5
    
    Expected output
    199.500000
    
  2. Example 2

    Input
    4
    100 1 0.5
    200 1 1
    100 0.5 1.5
    10 2 3
    
    Expected output
    405.500000