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.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().E();
	}
	void E()
	{
		int n = sc.nextInt();
		double t = sc.nextDouble();
		ArrayList<Ball> balls = new ArrayList<Ball>();
		for(int i = 0; i < n; i++) {
			balls.add(new Ball(i, sc.nextDouble(), sc.nextDouble(), sc.nextDouble()));
		}
		Collections.sort(balls);
		double crt_time = 0.0;
		while(true) {
			double nxt_duration = t - crt_time;
			int ball_idx = -10;
			for(int i = 1; i < n; i++) {
				double vd = balls.get(i-1).v - balls.get(i).v;
				if(vd > 0.0) {
					double nt =  Math.abs(balls.get(i).x - balls.get(i-1).x) / vd;
					if(nt < nxt_duration) {
						nxt_duration = nt; ball_idx = i-1; 
					}
				}
			}
			crt_time += nxt_duration;
			//System.out.println("" + ball_idx + " " + nxt_duration + " " + crt_time);
			for(int i = 0; i < n; i++) {
				balls.get(i).x += balls.get(i).v * nxt_duration;
			}
			if(crt_time >= t) {
				Collections.sort(balls, new Comparator<Ball> () {
					public int compare(Ball b1, Ball b2) {
						if(b1.id < b2.id) return -1;
						if(b1.id > b2.id) return 1;
						return 0;
					}
				});
				//for(int id = 0; id < n; id++) 
					for(int i = 0; i < n; i++) 
						//if(balls.get(i).id == id)
							System.out.printf("%.8f\n", balls.get(i).x);
				
				break;
			}
			{
				double m1 = balls.get(ball_idx).m;
				double v1 = balls.get(ball_idx).v;
				double m2 = balls.get(ball_idx+1).m;
				double v2 = balls.get(ball_idx+1).v;
				double nv1 = ((m1 - m2) * v1 + 2.0 * m2 * v2) / (m1 + m2);
				double nv2 = ((m2 - m1) * v2 + 2.0 * m1 * v1) / (m1 + m2);
				balls.get(ball_idx).v = nv1;
				balls.get(ball_idx+1).v = nv2;
			}
		}
		
	}
	class Ball implements Comparable<Ball>{
		int id;
		double x, v, m;
		Ball() { };
		Ball(int id, double x, double v, double m) {
			this.id = id; this.x = x; this.v = v; this.m = m;
		}
		public int compareTo(Ball other) {
			if(x < other.x) return -1;
			if(x > other.x) return 1;
			return 0;
		}
	}

	void D()
	{
		int n = sc.nextInt(), r1 = sc.nextInt(), r2 = sc.nextInt();
		int [] neib = new int[n+1];
		for(int i = 1; i <= n; i++) {
			if(i == r1) continue;
			neib[i] = sc.nextInt();
		}
		//for(int i = 1; i <= n; i++) System.out.print(neib[i]); System.out.println();
		ArrayList<Integer> path = new ArrayList<Integer>();
		for(int node = r2; node != r1; node = neib[node]) {
			path.add(node);
		}
		path.add(r1);
		//for(int i = 0; i < path.size(); i++) System.out.print(path.get(i)); System.out.println();
		for(int i = path.size() - 2; i >= 0; i--) {
			neib[path.get(i+1)] = path.get(i);
		}
		//for(int i = 1; i <= n; i++) System.out.print(neib[i]); System.out.println();
		for(int i = 1; i <= n; i++) {
			if(i == r2) continue;
			System.out.print("" + neib[i] + " ");
		}
		System.out.println();
		
	}
	void C()
	{
		StringBuilder line = new StringBuilder(sc.nextLine());
		line.append(',');
		sc = new Scanner(line.toString()).useDelimiter(",");
		TreeSet<Integer> page_set = new TreeSet<Integer>();
		while(sc.hasNextInt()) {
			int n = sc.nextInt();
			//System.out.println(n);
			page_set.add(n);
		}
		ArrayList<Integer> from = new ArrayList<Integer>();
		ArrayList<Integer> to = new ArrayList<Integer>();
		int cand = -100;
		for(Integer page: page_set) {
			if(page > cand+1) {
				if(cand >= 0) to.add(cand);
				from.add(page);
			}
			cand = page;
		}
		to.add(cand);
		for(int i = 0; i < from.size(); i++) {
			if(i > 0) System.out.print(",");
			if(from.get(i).equals(to.get(i))) 
				System.out.print(from.get(i));
			else
				System.out.print("" + from.get(i) + "-" + to.get(i));
		}
		System.out.println();
		
	}
	void B()
	{
		int n = sc.nextInt(), m = sc.nextInt();
		int [] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		int ans = 0;
		for(int i = 0; i < m; i++) {
			if(a[i] < 0) ans -= a[i];
			else break;
		}
		System.out.println(ans);
	}
	void A()
	{
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		a[n] = a[0];
		int min_v = Math.abs(a[1] - a[0]), min_idx = 0;
		for(int i = 1; i < n; i ++ ) {
			int work = Math.abs(a[i+1] - a[i]);
			if(work < min_v) {
				min_v = work;
				min_idx = i;
			}
		}
		System.out.println("" + (min_idx % n + 1) + " " + ((min_idx + 1) % n + 1));
	}
}