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.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Collisions {
	static final double INF = 1e9;
	static final double EXP = 1e-9; 
	
	static class Ball implements Comparable<Ball> {
		double x;
		double speed;
		double weight;
		
		Ball() {
			;
		}
		
		Ball(double x, double speed, double weight) {
			this.x = x;
			this.speed = speed;
			this.weight = weight;
		}
		
		static double timeToHit(Ball a, Ball b) {
			double dist = a.x - b.x;
			double speed = b.speed - a.speed;
			if (speed == 0.0) {
				return INF;
			}
			double time = dist / speed;
			if (time <= 0) {
				return INF;
			}
			else {
				return time;
			}
		}
		
		void run(double time) {
			x += speed * time;
		}
		
		static void hit(Ball a, Ball b) {
			double newA = ((a.weight - b.weight) * a.speed + 2.0 * b.weight * b.speed) / (a.weight + b.weight);
			double newB = ((b.weight - a.weight) * b.speed + 2.0 * a.weight * a.speed) / (a.weight + b.weight);
			a.speed = newA;
			b.speed = newB;
		}
		
		@Override
		public String toString() {
			return x + " &" + speed + "m/s (" + weight + "kg)";
		}

		@Override
		public int compareTo(Ball o) {
			return (int) (x - o.x);
		}
	}
	
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("test.in"));
//			System.setOut(new PrintStream(new FileOutputStream("test.out")));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			int n = cin.nextInt();
			double t = cin.nextDouble();
			Ball[] ball = new Ball[n];
			for (int i = 0; i < n; i ++) {
				double x = cin.nextDouble();
				double v = cin.nextDouble();
				double m = cin.nextDouble();
				ball[i] = new Ball(x, v, m);
			}
			
			double cur = 0;
			while(true) {				
				double minTime = INF;
				for (int i = 0; i < n; i ++) {
					for (int j = i + 1; j < n; j ++) {
						double time = Ball.timeToHit(ball[i], ball[j]);
						if (time < minTime) {
							minTime = time;
						}
					}
				}
				
				if (minTime + cur < t) {
					for (int i = 0; i < n; i ++) {
						ball[i].run(minTime);
					}
					
					for (int i = 0; i < n; i ++) {
						for (int j = i + 1; j < n; j ++) {
							if (Math.abs(ball[i].x - ball[j].x) < EXP) {
								ball[i].x = ball[j].x;
								Ball.hit(ball[i], ball[j]);
							}
						}
					}
					
					cur += minTime;
				}
				else {
					for (int i = 0; i < n; i ++) {
						ball[i].run(t - cur);
					}
					break;
				}
			}
			
			for (int i = 0; i < n; i ++) {
				System.out.printf("%.6f\n", ball[i].x);
			}
		}
	}
}