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.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class E_Collisions {

    /**
     * 10:56
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        
        Ball[] balls = new Ball[n];
        for (int i = 0; i < n; i++) {
            balls[i] = new Ball(i, sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(balls, new Comparator<Ball>() {
            public int compare(Ball o1, Ball o2) {
                if(o1.x == o2.x) return 0;
                return o1.x < o2.x ? -1 : 1;
            }
        });
        
        double INF = 1000000000.0;
        
        double ct = 0;
        while(true){
            double mint = INF;
            Ball b1 = null, b2 = null;
            for (int i = 0; i < n-1; i++) {
                if(balls[i].v - balls[i+1].v <= 0) continue;
                double tmpt = (balls[i+1].x - balls[i].x) / (balls[i].v - balls[i+1].v);
                if(tmpt < mint){
                    mint = tmpt;
                    b1 = balls[i];
                    b2 = balls[i+1];
                }
            }
            if(b1 == null) mint = t - ct + 1;
            
            boolean flg = false;
            if(ct+mint > t){
                mint = t - ct;
                flg = true;
            }
            ct += mint;
            for (int i = 0; i < n; i++) {
                balls[i].x += mint * balls[i].v;
            }
            if(! flg){
                double b1v = ((b1.m-b2.m)*b1.v + 2*b2.m*b2.v)/(b1.m+b2.m);
                double b2v = ((b2.m-b1.m)*b2.v + 2*b1.m*b1.v)/(b1.m+b2.m);
                b1.v = b1v;
                b2.v = b2v;
            }else{
                break;
            }
        }
        
        
        Arrays.sort(balls, new Comparator<Ball>() {
            public int compare(Ball o1, Ball o2) {
                return o1.index - o2.index;
            }
        });
        for (int i = 0; i < n; i++) {
            System.out.println(balls[i].x);
        }
    }

    static class Ball{
        int index;
        double x,v,m;
        public Ball(int index, double x, double v, double m){
            this.index = index;
            this.x = x;
            this.v = v;
            this.m = m;
        }
    }
}