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.*;
import java.io.*;
import static java.lang.Math.*;
import java.math.*;

public class Main implements Runnable {
	BufferedReader in;
	PrintStream out;
    //PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

	public static void main(String [] args) throws Exception {
		new Thread(new Main()).start();
	}

	void printExit(String s) {
		System.out.println(s);
		System.exit(0);
	}

	public void run() {
		try {
            double eps = 1e-7;
            Locale.setDefault(Locale.US);
            String s;
            in = new BufferedReader(new InputStreamReader(System.in));
            //in = new BufferedReader(new FileReader("cruel.in"));
            //out = new PrintWriter("cruel.out");
            out = new PrintStream(System.out);
			int n = nextInt(); double t = nextDouble();
            double time = 0; double t1, t2,v1,v2; int min;
            int perm [] = new int [n];
            int p [] = new int [n];
            for (int i= 0; i<n; i++){
                perm[i]=i;
            }
            int m [] = new int [n];
            double v [] = new double [n];
            double x [] = new double [n];
            for (int i=0; i< n; i++){
                x[i] = nextDouble();
                v[i] = nextDouble();
                m[i] = nextInt();
            }
            for (int i=0; i<n; i++){
                for (int j=i; j>0; j--){
                    if (x[j] < x[j-1]){
                        t2 = x[j]; x[j] = x[j-1]; x[j-1] = t2;
                        t2 = v[j]; v[j] = v[j-1]; v[j-1] = t2;
                        min = m[j]; m[j] = m[j-1]; m[j-1] = min;
                        min = perm[j]; perm[j] = perm[j-1]; perm[j-1] = min;  
                    }
                }
            }
            for (int i=0; i<n; i++){
                p[perm[i]] = i;
            }
            while(true){
               t1 = t+1; min = -1;
               for (int i=0; i<n-1; i++){
                   if (v[i]>v[i+1]){
                       t2 = (x[i+1]-x[i])/(v[i]-v[i+1]);
                       if (t2 < t1) {t1=t2; min = i;}
                   }
               }
               if ((time+t1)>t){
                  t2 = t-time;
                  for (int i =0; i< n; i++){
                      x[i] = x[i] + t2*v[i];
                  }
                  for (int i =0; i< n; i++){
                      out.println(x[p[i]]);
                  }
                  break;
               }else{
                  for (int i =0; i< n; i++){
                        x[i] = x[i] + t1*v[i];
                  }
                  v1 = v[min]; v2= v[min+1];
                  v[min] = ((m[min] - m[min+1])*v1 + 2*m[min+1]*v2)/(m[min]+m[min+1]);
                  v[min+1] = ((m[min+1] - m[min])*v2 + 2*m[min]*v1)/(m[min]+m[min+1]);
                  time+=t1; 
               }
            }
           //out.close();
        }
		catch (Exception e) {
			e.printStackTrace();
		}
	}

	 boolean seekForToken() {
 		try {
			while (!st.hasMoreTokens()) {
				String s = in.readLine();
				if (s == null) {
				 	return false;
				}
			 	st = new StringTokenizer(s);
			}
			return true;
		}
		catch (IOException e) {
		 	e.printStackTrace();
		 	return false;
		}
 	}

 	 int nextInt() {
		return Integer.parseInt(nextToken());
 	}

 	 long nextLong() {
		return Long.parseLong(nextToken());
 	}

 	 double nextDouble() {
		return Double.parseDouble(nextToken());
 	}

 	 BigInteger nextBigInteger() {
 	 	return new BigInteger(nextToken());
 	}

 	 String nextToken() {
 	 	seekForToken();
 	 	return st.nextToken();
 	}

}