This page is still under construction.

Parts of this page are still being built. What you see may change.

Do It

Time limit8sMemory limit512 MB

Summary
Integrate a product of N sine functions over [0, R], with N up to 16, to absolute or relative error 1e-8.
Level

Hard8 of 10

Topics
Math, Divide and conquer, Recursion, Implementation
Solved
No attempts yet

Problem

Giving contest problems nice backgrounds is sometimes difficult. So this problem stays simple: write a program that calculates the value of the following formula, where the parameters N, R, Ai, ωi, and φi are all given:

∫0R[∏i=1NAisin⁡(ωit+φi⋅π180)]dt\int_{0}^{R}{\left[\prod_{i=1}^{N}{A_i \sin{\left( \omega_i t + \varphi_i \cdot \frac{\pi}{180} \right)}}\right]dt}

Input

The input consists of a series of datasets, each with the following format:

N R
A1 ω1 φ1
A2 ω2 φ2
...
AN ωN φN

The numbers in the input are all integers and satisfy the following conditions: 1 ≤ N ≤ 16, 1 ≤ R ≤ 104, 1 ≤ Ai ≤ 10, 0 ≤ ωi ≤ 100, and 0 ≤ φi ≤ 360.

The end of input is indicated by N = R = 0. This is not part of any dataset, so it should not be processed.

Output

For each dataset, print the result of the integration on one line. The result may be printed with an arbitrary number of fractional digits, but the relative or absolute error must be at most 10-8.

Examples1

  1. Example 1

    Input
    1 1
    1 1 0
    0 0
    
    Expected output
    0.45969769413186