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.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {}
		
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	int N;
	double T;
	Ball[] b;
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		N = nextInt();
		T = nextDouble();
		b = new Ball [N];
		for (int i = 0; i < N; i++)
			b[i] = new Ball(nextDouble(), nextDouble(), nextDouble());
		int[] u = new int [100];
		int[] v = new int [100];
		while (T > 1e-11) {
			double dt = 1e100;
			int usz = 0;
			int vsz = 0;
			for (int i = 0; i < N; i++)
				for (int j = i + 1; j < N; j++) {
					if (i != j && dt(b[i], b[j]) > 1e-6) {
						if (dt > dt(b[i], b[j])) {
							dt = dt(b[i], b[j]);
							usz = 0;
							vsz = 0;
							u[usz++] = i;
							v[vsz++] = j;
						} else if (abs(dt - dt(b[i], b[j])) < 1e-6) {
							u[usz++] = i;
							v[vsz++] = j;
						}
					}
				}
			dt = min(T, dt);
			for (int i = 0; i < N; i++)
				b[i].update(dt);
			for (int i = 0; i < usz; i++)
				update(b[u[i]], b[v[i]]);
			T -= dt;
		}
		for (Ball bl : b)
			out.println(bl.x);
		out.close();
	}
	
	void update(Ball b1, Ball b2) {
		double v1 = ((b1.m - b2.m) * b1.v + 2.0 * b2.m * b2.v) / (b1.m + b2.m);
		double v2 = ((b2.m - b1.m) * b2.v + 2.0 * b1.m * b1.v) / (b1.m + b2.m);
		b1.v = v1;
		b2.v = v2;
	}

	double dt(Ball b1, Ball b2) {
		double dv = b2.v - b1.v;
		double dx = b2.x - b1.x;
		if (abs(dx) < 1e-6) {
			return 1e100;
		}
		if (abs(dv) < 1e-6) {
			return 1e100;
		}
		if (-dx / dv < -1e-6)
			return 1e100;
		return max(0.0, -dx / dv);
	}
	
	class Ball {
		double x;
		double v;
		double m;
		
		Ball(double x, double v, double m) {
			this.x = x;
			this.v = v;
			this.m = m;
		}

		void update(double dt) {
			x += dt * v;
		}
		
		@Override
		public String toString() {
			return "<" + x + ", " + v + ", " + m + ">";
		}
	}
	
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}