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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class PE implements Runnable {
	private BufferedReader rd;
	private StringTokenizer tok = null;
	private Ball[] balls;
	private double maximumTime;
	private PriorityQueue<Collision> collisionQueue;
	static final double EPS = 1e-10;
	private double currentTime;
	private int n;
	
	public static void main(String[] args) {
		new Thread(new PE()).start();
	}

	@Override
	public void run() {
		try {
			solve();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}
	
	static class Ball {
		public final int initialIndex;
		public int index;
		public double position;
		public double speed;
		public final double mass;
		
		public Ball(int initialIndex, double position, double speed, double mass) {
			this.initialIndex = initialIndex;
			this.position = position;
			this.speed = speed;
			this.mass = mass;
		}
		
		@Override
		public String toString() {
			return String.format("ball { p=%.4f, s=%.4f, m=%.4f }", position, speed, mass);
		}
	}
	
	static class Collision implements Comparable<Collision> {
		public Ball left;
		public Ball right;
		public final double time;
		
		public Collision(Ball left, Ball right, double time) {
			this.left = left;
			this.right = right;
			this.time = time;
		}

		@Override
		public int compareTo(Collision o) {
			if (time < o.time) {
				return -1;
			} else if (time > o.time) {
				return 1;
			}
			return 0;
		}
		
		@Override
		public String toString() {
			return String.format("collision { left=%s, right=%s, time=%.4f }", left, right, time);
		}
	}

	class BallPositionComparator implements Comparator<Ball> {

		@Override
		public int compare(Ball left, Ball right) {
			if (left.position < right.position) {
				return -1;
			} else if (left.position > right.position) {
				return 1;
			}
			return 0;
		}
		
	}
	
	public Collision findCollision(Ball left, Ball right, double minimumTime, double maximumTime) {
		if (Math.abs(left.speed - right.speed) < EPS) {
			return null;
		}
		
		double deltaTime = (right.position - left.position) / (left.speed - right.speed);
		double time = currentTime + deltaTime;
		if ((time > minimumTime - EPS) && (time < maximumTime + EPS)) {
			return new Collision(left, right, time);
		} else {
			return null;
		}
	}
	
	private void solve() throws IOException {
		rd = new BufferedReader(new InputStreamReader(System.in));
		
		Locale.setDefault(Locale.US);
		
		n = nextInt();
		maximumTime = nextInt();
		
		balls = new Ball[n];
		for (int i = 0; i < n; ++i) {
			int position = nextInt();
			int speed = nextInt();
			int mass = nextInt(); 
			
			balls[i] = new Ball(i, position, speed, mass);
		}
		
		Arrays.sort(balls, new BallPositionComparator());
		
		for (int i = 0; i < n; ++i) {
			balls[i].index = i;
		}
		
		currentTime = 0;
		
		collisionQueue = new PriorityQueue<Collision>();
		for (int i = 0; i < n - 1; ++i) {
			Collision collision = findCollision(balls[i], balls[i + 1], currentTime, maximumTime);
			if (collision == null) {
				continue;
			}
			
			collisionQueue.add(collision);
		}
		
		while (!collisionQueue.isEmpty()) {
			Collision collision = collisionQueue.poll();
			
			if (collision.time > currentTime - EPS) {
				processTime(collision.time);
				processCollision(collision);
			} else {
				continue;
			}
		}
		
		processTime(maximumTime);
		
		double[] result = new double[n];
		for (int i = 0; i < n; ++i) {
			Ball ball = balls[i];
			result[ball.initialIndex] = ball.position;
		}
		
		PrintWriter wr = new PrintWriter(System.out);
		for (int i = 0; i < n; ++i) {
			wr.println(String.format("%.12f", result[i]));
		}
		wr.close();
		
		rd.close();
	}

	private void processTime(double time) {
		double delta = time - currentTime;
		currentTime = time;
		
		for (int i = 0; i < n; ++i) {
			balls[i].position = balls[i].position + balls[i].speed * delta;   
		}
	}

	private void processCollision(Collision collision) {
		Ball left = collision.left;
		Ball right = collision.right;
		
		if (Math.abs(left.position - right.position) > EPS) {
			return;
		}

		double leftSpeed = left.speed;
		double rightSpeed = right.speed;
		left.speed = ((left.mass - right.mass) * leftSpeed + 2 * right.mass * rightSpeed) / (left.mass + right.mass);
		right.speed = ((right.mass - left.mass) * rightSpeed + 2 * left.mass * leftSpeed) / (left.mass + right.mass);
		
		int li = left.index;
		int ri = right.index;
		
		Collision newCollision;
		
		if (li != 0) {
			newCollision = findCollision(balls[li - 1], balls[li], currentTime, maximumTime);
			if (newCollision != null) {
				collisionQueue.add(newCollision);
			}
		}
		
		if (ri != n - 1) {
			newCollision = findCollision(balls[ri], balls[ri + 1], currentTime, maximumTime);
			if (newCollision != null) {
				collisionQueue.add(newCollision);
			}
		}
	}

	private int nextInt() throws IOException {
		while (true) {
			if ((tok != null) && (tok.hasMoreTokens())) {
				break;
			}
			tok = new StringTokenizer(rd.readLine());
		}
		return Integer.parseInt(tok.nextToken());
	}
}