Problem: On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored.

The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds will be: 

<image>.

Your task is to find out, where each ball will be t seconds after.

Input

The first line contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 100) — amount of balls and duration of the process. Then follow n lines, each containing three integers: xi, vi, mi (1 ≤ |vi|, mi ≤ 100, |xi| ≤ 100) — coordinate, speed and weight of the ball with index i at time moment 0.

It is guaranteed that no two balls have the same coordinate initially. Also each collision will be a collision of not more than two balls (that is, three or more balls never collide at the same point in all times from segment [0;t]).

Output

Output n numbers — coordinates of the balls t seconds after. Output the numbers accurate to at least 4 digits after the decimal point.

Examples

Input

2 9
3 4 5
0 7 8


Output

68.538461538
44.538461538


Input

3 10
1 2 3
4 -5 6
7 -8 9


Output

-93.666666667
-74.666666667
-15.666666667

Solution (in JAVA):

Solution:

import java.util.Scanner;


public class Collisions {
    public static double [] x;
    public static double [] v;
    public static double [] m;

    public static void main(String [] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int t = in.nextInt();
        x = new double[n];
        v = new double[n];
        m = new double[n];
        int pos [] = new int[n];

        for (int i = 0; i < n; i++){
            x[i] = in.nextDouble();
            v[i] = in.nextDouble();
            m[i] = in.nextDouble();
            pos[i] = i+1;
        }

        for (int i = 0; i < n; i++)
            for(int j = i+1; j<n; j++)
                if(x[i]>x[j]){
                    double q = x[i]; x[i] = x[j]; x[j] = q;
                    q = v[i]; v[i] = v[j]; v[j] = q;
                    q = m[i]; m[i] = m[j]; m[j] = q;
                    int k = pos[i]; pos[i] = pos[j]; pos[j] = k;
                }

        double time = 0;
        int p = 0;

        while(time < t){
            double minT = Double.MAX_VALUE;
            for (int i = 0; i < n-1; i++){
                double dTime = getTime(i);
                if(dTime < minT) {
                    minT = dTime;
                    p = i;
                }
            }

            if(time+minT>=t) minT = t - time;
            time+=minT;

            for (int j = 0; j < n; j++)
                x[j] = x[j]+v[j]*minT;

            double x1 = ((m[p]-m[p+1])*v[p]+2*m[p+1]*v[p+1])/(m[p]+m[p+1]);
            double x2 = ((m[p+1]-m[p])*v[p+1]+2*m[p]*v[p])/(m[p]+m[p+1]);
            v[p] = x1;
            v[p+1] = x2;
        }


          for (int i = 0; i < n; i++)
            for(int j = i+1; j<n; j++)
                if(pos[i]>pos[j]){
                    double q = x[i]; x[i] = x[j]; x[j] = q;
                    int k = pos[i]; pos[i] = pos[j]; pos[j] = k;
                }

        for (int i = 0; i < n; i++)
            System.out.printf("%.9f\n",x[i]);
    }


    public static double getTime(int index){
        if(v[index] > v[index+1]){
            return Math.abs((x[index+1]-x[index])/(v[index+1]-v[index]));
        }else
            return Double.MAX_VALUE;
    }
}