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

/**
 * Created by mostafa on 6/10/17.
 */
public class Collision {
    static double diff = 1e-5;
    static double diff2 = diff * 100;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), t = sc.nextInt();
        Ball[] b = new Ball[n];
        for(int i = 0; i < n; i++) {
            b[i] = new Ball(sc.nextInt(), sc.nextInt(), sc.nextInt(), i);
        }
        double curT = 0;
        Arrays.sort(b);

        while(curT < t) {
            double nextCollide = -1;
            int coll = -1;
            for(int i = 0; i < n - 1; i++) {
                double ti = timeToCollide(b[i], b[i + 1]);
                if(ti != -1) {
                    if (nextCollide == -1 || ti < nextCollide) {
                        nextCollide = ti;
                        coll = i;
                    }
                }
            }

            if(nextCollide == -1 || curT + nextCollide > t)
                break;


            for(int i = 0; i < n; i++)
                b[i].x += b[i].v * nextCollide;


            updateV(b[coll], b[coll + 1]);

            curT += nextCollide;
        }

        for(int i = 0; i < n; i++)
            b[i].x += b[i].v * (t - curT);

        double[] ans = new double[n];
        for(int i = 0; i < n; i++)
            ans[b[i].i] = b[i].x;

        for(int i = 0; i < n; i++)
            System.out.println(ans[i]);
    }

    static void updateV(Ball b1, Ball b2) {
        double v1 = b1.v, v2 = b2.v, m1 = b1.m , m2 = b2.m;
        b1.v = ((m1 - m2) * v1 + 2 * m2 * v2) / (m1 + m2);
        b2.v = ((m2 - m1) * v2 + 2 * m1 * v1) / (m1 + m2);
    }

    static double timeToCollide(Ball b1, Ball b2) {
        if(b1.x > b2.x) {
            Ball tmp = b1;
            b1 = b2;
            b2 = tmp;
        }

        if(b1.v <= b2.v)
            return -1;

        if(b1.v * b2.v > 0) {
            return (b2.x - b1.x) / (b1.v - b2.v);
        }
        else
            return (b2.x - b1.x) / (Math.abs(b1.v) + Math.abs(b2.v));
    }

    static class Ball implements Comparable<Ball>{
        double x, v, m;
        int i;
        Ball(double x, double v, double m, int i) {
            this.x = x;
            this.v = v;
            this.m = m;
            this.i = i;
        }

        @Override
        public int compareTo(Ball b) {
            return Double.compare(x, b.x);
        }

        @Override
        public String toString() {
            return String.format("#%d: %f", i, x);
        }
    }
}