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.*;
import static java.lang.Math.*;

public class E {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), t = in.nextInt();
        double T = t;
        Ball[] balls = new Ball[n];
        for (int i = 0; i < balls.length; i++) {
            balls[i] = new Ball(in.nextInt(), in.nextInt(), in.nextInt());
        }
        while (true) {
            int b1 = -1, b2 = -1;
            double minTime = 1e5;
            for (int i = 0; i < balls.length; i++) {
                for (int j = i + 1; j < balls.length; j++) {
                    double time = (abs(balls[i].x - balls[j].x) ) / (abs(balls[i].v) + abs(balls[j].v));
                    double tt = balls[i].collisionTime(balls[j]);
                    time = tt;
                    if (minTime > time) {
                        minTime = time;
                        b1 = i;
                        b2 = j;
                    }
                }
            }
            
            if (T < minTime )
                break;
            T -= minTime ;
            
            for (int i = 0; i < balls.length; i++) {
                balls[i].x += minTime * balls[i].v;
            }
            
            double v1 = balls[b1].v;
            double v2 = balls[b2].v;
            double m1 = balls[b1].m;
            double m2 = balls[b2].m;
            
            balls[b1].v = ((m1 - m2) * v1 + 2.0 * m2 * v2) / (m1 + m2);
            balls[b2].v = ((m2 - m1) * v2 + 2.0 * m1 * v1) / (m1 + m2);
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < balls.length; i++) {
            sb.append((balls[i].x + T * balls[i].v) + "\n");
        }
        System.out.print(sb);
    }
}

class Ball {
    double x, v, m;
    public Ball(double x, double v, double m) {
        super();
        this.x = x;
        this.v = v;
        this.m = m;
    }
    
    public double collisionTime(Ball o) {
        Ball a = this, b = o;
        if (x > o.x) {
            a = o;
            b = this;
        }
        
        double lo = 0, hi = 1e6;
        for (int itr = 0; itr < 100; itr++) {
            double t = (lo + hi) / 2.0;
            double xa = a.x + t*a.v;
            double xb = b.x + t*b.v;

            if (xa < xb)
                lo = t;
            else
                hi = t;
        }
        
        return lo;
    }

    public String toString() {
        return "[m=" + m + ", v=" + v + ", x=" + x + "]";
    }
    
    
}