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 javax.swing.event.ListDataEvent;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class J implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());

        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new J().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    double timeCrash(double x, double v, double ox, double ov) {
        if (x == ox) return Double.MAX_VALUE;
        if (x <= ox) {
            if (v <= 0 && ov >= 0) return Double.MAX_VALUE;
            if (v >= 0 && ov <= 0) {
                return (ox - x) / (Math.abs(v) + Math.abs(ov));
            }
            if (v >= 0 && ov >= 0) {
                if (ov >= v) return Double.MAX_VALUE;
                return (x - ox) / (ov - v);
            }
            if (v <= 0 && ov <= 0) {
                if (v <= ov) return Double.MAX_VALUE;
                return (x - ox) / (ov - v);
            }
            throw new RuntimeException();
        } else {
            return timeCrash(ox, ov, x, v);
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int t = readInt();
        double[] x = new double[n];
        double[] v = new double[n];
        int[] m = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = readInt();
            v[i] = readInt();
            m[i] = readInt();
        }

        double timeSpend = 0;
        double eps = 1e-7;
        while (timeSpend < t) {
            double closest = Double.MAX_VALUE;
            int ii = -1, jj = -1;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    double time = timeCrash(x[i], v[i], x[j], v[j]);
                    if (time < closest) {
                        closest = time;
                        ii = i;
                        jj = j;
                    }
                }
            }
            if (t - timeSpend < closest) {
                double timeApply = t - timeSpend;
                for (int i = 0; i < n; i++) {
                    x[i] = x[i] + timeApply * v[i];
                }
                break;
            } else {
                double timeApply = closest;
                timeSpend += timeApply;
                for (int i = 0; i < n; i++) {
                    x[i] = x[i] + timeApply * v[i];
                }
                for (int i = 0; i < n; i++) {
                    for (int j = i + 1; j < n; j++) {
                        if (Math.abs(x[i] - x[j]) < eps) {
                            ii = i;
                            jj = j;
                            x[ii] = x[jj] = (x[ii] + x[jj]) / 2;
                            double v1 = ((m[ii] - m[jj]) * v[ii] + 2 * m[jj] * v[jj]) / (m[ii] + m[jj]);
                            double v2 = ((m[jj] - m[ii]) * v[jj] + 2 * m[ii] * v[ii]) / (m[ii] + m[jj]);
                            v[ii] = v1;
                            v[jj] = v2;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            out.println(x[i]);
        }

    }
}