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.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PandaScanner in = new PandaScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		E solver = new E();
		solver.solve(1, in, out);
		out.close();
	}
}

class E {
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        int n = in.nextInt();
        double t = in.nextInt();

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

        int lastCollided = -1;
        while (t > 0) {
            double next = Double.POSITIVE_INFINITY;
            int collideIdx = 0;
            for (int i = 0; i < n - 1; i++) {
                double toCollide = balls[i].collide(balls[i + 1]);
                if (next > toCollide && i != lastCollided) {
                    next = toCollide;
                    collideIdx = i;
                }
            }
            lastCollided = collideIdx;
            next = Math.min(next, t);
            for (int i = 0; i < n; i++) {
                balls[i].x += balls[i].v * next;
            }
            t -= next;
            balls[collideIdx].update(balls[collideIdx + 1]);
        }
        double finalPosition[] = new double[n];
        for (int i = 0; i < n; i++) {
            finalPosition[balls[i].idx] = balls[i].x;
        }
        for (int i = 0; i < n; i++) {
            out.printf("%.9f\n", finalPosition[i]);
        }
    }
    public class Ball implements Comparable<Ball> {
        int idx;
        double x;
        double v;
        double m;
        public Ball(int idx, double x, double v, double m) {
            this.idx = idx;
            this.x = x;
            this.v = v;
            this.m = m;
        }
        public double collide(Ball o) {
            double diffX = o.x - x;
            double diffV = v - o.v;
            if (diffV == 0 || diffX * diffV < 0) {
                return Double.POSITIVE_INFINITY;
            }
            return diffX / diffV;
        }
        public void update(Ball o) {
            double v1 = ((m - o.m) * v + 2.0 * o.m * o.v) / (m + o.m);
            double v2 = ((o.m - m) * o.v + 2.0 * m * v) / (m + o.m);
            v = v1;
            o.v = v2;
            x -= 1e-10;
            o.x += 1e-10;
        }
        public int compareTo(Ball o) {
            return Double.compare(x, o.x);
        }
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }