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 Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int tMax = in.nextInt();

        Ball[] balls = new Ball[n];

        for (int i = 0; i < n; i++) {
            balls[i] = new Ball(in.nextInt(), in.nextInt(), in.nextInt());
        }

        double t = 0;
        while (t < tMax) {
            double tDelta = findCollision(balls);

            tDelta = Math.min(tDelta, tMax - t);
            t += tDelta;

            recalculatePositions(balls, tDelta);
            recalculateSpeed(balls);
        }

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

    private static void recalculatePositions(Ball[] balls, double t) {
        for (int i = 0; i < balls.length; i++) {
            balls[i].x += balls[i].v * t;
        }
    }

    private static void recalculateSpeed(Ball[] balls) {
        for (int i = 0; i < balls.length; i++) {
            for (int j = i + 1; j < balls.length; j++) {
                if (Math.abs(balls[i].x - balls[j].x) < 1e-6) {
                    double newVi = ((balls[i].m - balls[j].m) * balls[i].v + 2 * balls[j].m * balls[j].v) / (balls[i].m + balls[j].m);
                    double newVj = ((balls[j].m - balls[i].m) * balls[j].v + 2 * balls[i].m * balls[i].v) / (balls[i].m + balls[j].m);

                    balls[i].v = newVi;
                    balls[j].v = newVj;
                }
            }
        }
    }

    private static double findCollision(Ball[] balls) {
        double minT = Double.POSITIVE_INFINITY;
        for (int i = 0; i < balls.length; i++) {
            for (int j = i + 1; j < balls.length; j++) {
                // ignore "collision" case
                if (Math.abs(balls[i].x - balls[j].x) < 1e-6)
                    continue;

                double tBalls = balls[i].v - balls[j].v == 0
                        ? Double.POSITIVE_INFINITY
                        : (balls[j].x - balls[i].x) / (balls[i].v - balls[j].v);

                if (tBalls < 0)
                    tBalls = Double.POSITIVE_INFINITY;

                if (tBalls < minT)
                    minT = tBalls;
            }
        }

        return minT;
    }

    private static class Ball {
        public double x;
        public double v;
        public int m;

        public Ball(int x, int v, int m) {
            this.x = x;
            this.v = v;
            this.m = m;
        }
    }
}