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.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Collisions
{
	static double eps = 1e-8;
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double t = sc.nextInt();
		double[] x = new double[n];
		double[] v = new double[n];
		double[] m = new double[n];
		for (int i = 0; i < n; i++)
		{
			x[i] = sc.nextInt();
			v[i] = sc.nextInt();
			m[i] = sc.nextInt();
		}
		double cum = 0;
		while(true)
		{
			double min = 1e9;
			int col1 = -1;
			int col2 = -1;
			for (int i = 0; i < n; i++)
				for (int j = i+1; j < n; j++)
				{
					if(i != j)
					{
						double col = 1.0*(x[j]-x[i])/(v[i]-v[j]);
						if(col > eps)
						{
							if(col+eps < min)
							{
								min = col;
								col1 = i;
								col2 = j;
							}
						}
					}
				}
			if(col1 == -1 || col2 == -1)
				break;
			if(cum + min > t+eps)
				break;
			
			for (int i = 0; i < n; i++)
				x[i] = x[i] + v[i]*min;
			
			for (int i = 0; i < m.length; i++)
				for (int j = i+1; j < m.length; j++)
					if(Math.abs(x[i]-x[j]) <= eps)
					{
						col1 = i;
						col2 = j;
						double tmp = ((m[col1]-m[col2])*v[col1] + 2*m[col2]*v[col2])/(m[col1]+m[col2]);
						v[col2] = ((m[col2]-m[col1])*v[col2] + 2*m[col1]*v[col1])/(m[col1]+m[col2]);
						v[col1] = tmp;
					}
			cum += min;
		}
		t -= cum;
		for (int i = 0; i < n; i++)
			x[i] = x[i] + v[i]*t;
		for (int i = 0; i < n; i++)
		{
			System.out.println(x[i]);
		}
	}
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) throws FileNotFoundException{	
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
		
		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}
		
		public boolean ready() throws IOException {return br.ready();}
	}
}