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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class _P034E{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, t;
	double[] xs, vs, ms;

	void run(){
		n=sc.nextInt();
		t=sc.nextInt();
		xs=new double[n];
		vs=new double[n];
		ms=new double[n];
		for(int i=0; i<n; i++){
			xs[i]=sc.nextInt();
			vs[i]=sc.nextInt();
			ms[i]=sc.nextInt();
		}
		solve();
	}

	void swap(double[] ds, int i, int j){
		double t=ds[i];
		ds[i]=ds[j];
		ds[j]=t;
	}

	void swap(int[] is, int i, int j){
		int t=is[i];
		is[i]=is[j];
		is[j]=t;
	}

	void solve(){
		int[] is=new int[n];
		int[] js=new int[n];
		for(int i=0; i<n; i++){
			is[i]=i;
		}
		for(int j=0; j<n; j++){
			for(int i=j+1; i<n; i++){
				if(xs[i]<xs[j]){
					swap(xs, i, j);
					swap(vs, i, j);
					swap(ms, i, j);
					swap(is, i, j);
				}
			}
		}
		for(int i=0; i<n; i++){
			js[is[i]]=i;
		}
		debug("is", is);
		debug("js", js);
		debug("x", xs);
		debug("v", vs);
		debug("m", ms);
		debug();
		double time=0;
		for(;;){
			debug("time", time);
			double tMin=Double.MAX_VALUE;
			int k=-1;
			for(int i=0; i<n-1; i++){
				double v1=vs[i];
				double v2=vs[i+1];
				boolean ok=false;
				ok|=v1>0&&v2+EPS>0;
				ok|=v1<0+EPS&&v2<0;
				ok|=v1>0&&v2<0;
				if(ok&&v1>v2){
					double v=v1-v2;
					double t=(xs[i+1]-xs[i])/v;
					if(t<tMin){
						tMin=t;
						k=i;
					}
				}
			}
			debug("tMin", tMin, "k", k);
			boolean collision=k>=0&&time+tMin<t+EPS;
			double dt;
			if(collision){
				dt=tMin;
			}else{
				dt=t-time;
			}
			for(int i=0; i<n; i++){
				xs[i]+=vs[i]*dt;
			}
			time+=dt;
			if(collision){
				double v1=vs[k], v2=vs[k+1];
				double m1=ms[k], m2=ms[k+1];
				double nv1=((m1-m2)*v1+2*m2*v2)/(m1+m2);
				double nv2=((m2-m1)*v2+2*m1*v1)/(m1+m2);
				vs[k]=nv1;
				vs[k+1]=nv2;
			}else{
				break;
			}
			debug("x", xs);
			debug("v", vs);
			debug("m", ms);
			debug();
			if(time+EPS>t){
				break;
			}
		}
		debug(time);
		for(int i=0; i<n; i++){
			println(xs[js[i]]+"");
		}
	}

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

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		// System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new _P034E().run();
	}
}