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

public class d implements Runnable {

	double oo = 1e18;
	
	class Ball {
		double x, v;
		int m;
		Ball(double xx, double vv, int mm) {
			x = xx; v = vv; m = mm;
		}
		double y(double time) {
			return x + v * time;
		}
		public String toString() {
			return String.format("(%f, %f, %d)", x, v, m);
		}
	}
	
	double E = 1e-5;
	double getIntersectTime(Ball a, Ball b) {
		double lo = 0, hi = t;
		for(int it = 0; it < 60; ++it) {
			double delta = (hi - lo) / 3;
			double t1 = lo + delta, t2 = hi - delta;
			double dist1 = Math.abs(a.y(t1) - b.y(t1)), dist2 = Math.abs(a.y(t2) - b.y(t2));
			if(dist1 < dist2) hi = t2;
			else lo = t1;
		}
		if(lo > E && Math.abs(a.y(lo) - b.y(lo)) <= E) {
			return lo;
		}
		return oo;
	}
	
	int n, t;
	Ball[] balls;
	
	double calc(Ball a, Ball b) {
		double top = (a.m - b.m) * a.v + 2 * b.m * b.v;
		double bot = a.m + b.m;
		return top / bot;
	}
	
	void update(Ball a, Ball b) {
		double v1 = calc(a, b), v2 = calc(b, a);
		a.v = v1;
		b.v = v2;
	}
	
	public void solve(FS in, PrintWriter out) {
		n = in.nextInt();
		t = in.nextInt();
		balls = new Ball[n];
		for(int i = 0; i < n; ++i) {
			balls[i] = new Ball(in.nextInt(), in.nextInt(), in.nextInt());
		}
		if(n == 1) {
			out.println(balls[0].y(t));
			return;
		}
		double totalTime = 0;
		while(true) {
			double smallestTime = oo;
			double[][] times = new double[n][n];
			for(int i = 0; i < n; ++i) {
				for(int j = i + 1; j < n; ++j) {
					double curTime = getIntersectTime(balls[i], balls[j]);
					times[i][j] = curTime;
					if(curTime < smallestTime) {
						smallestTime = curTime;
					}
				}
			}
			
			double newTotalTime = totalTime + smallestTime;
			if(newTotalTime < t) {
				for(Ball cur : balls) {
					cur.x = cur.y(smallestTime);
				}
				for(int i = 0; i < n; ++i) {
					for(int j = i + 1; j < n; ++j) {
						if(Math.abs(times[i][j] - smallestTime) <= E) {
							update(balls[i], balls[j]);
						}
					}
				}
				totalTime = newTotalTime;
				continue;
			}
			double remain = t - totalTime;
			for(Ball cur : balls) {
				cur.x = cur.y(remain);
			}
			for(Ball cur : balls) {
				out.println(cur.x);
			}
			return;
		}
	}
	
	public void run() {
		System.err.println("go!");
		FS in = new FS();
		PrintWriter out = new PrintWriter(System.out);
		solve(in, out);
		out.close();
	}
	
	public static void main(String[] args) {
		new Thread(null, new d(), "lmao", 1L<<28).start();
	}
	static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while(!st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}