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 static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class E implements Runnable
{
    String file = "input";
    
    void init() throws IOException
    {
        //input = new BufferedReader(new FileReader(file + ".in"));
        input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }
    
    void solve() throws IOException
    {
        int n = nextInt(), t = nextInt();
        this.t = t;
        double[] x = new double[n];
        double[] v = new double[n];
        double[] m = new double[n];
        for(int i = 0; i < n; i++)
        {
            x[i] = nextDouble();
            v[i] = nextDouble();
            m[i] = nextDouble();
        }
        simul(x, v, m, 0, 0);
        for(int i = 0; i < n; i++) out.printf("%.6f ", x[i]);
    }   
    int t;
    double EPS = 1e-9;
    void simul(double[] x, double[] v, double[] m, double T, int count)
    {
        //print(x);
        //print(v);
        //print(m);
        //print(T);
        // if(count > 100) return;
        //if(T > t + EPS) return;
        ArrayList<Integer> Ri = new ArrayList<Integer>();
        ArrayList<Integer> Rj = new ArrayList<Integer>();
        double nextT = t + 1;
        for(int i = 0; i < x.length; i++)
            for(int j = i + 1; j < x.length; j++)
            {
                if(abs(v[i] - v[j]) < EPS) continue;
                double nt = (x[i] - x[j]) / (v[j] - v[i]);
                if(nt < EPS) continue;
                if(nextT - EPS > nt)
                {
                    nextT = nt;
                    Ri = new ArrayList<Integer>();
                    Rj = new ArrayList<Integer>();
                    Ri.add(i);
                    Rj.add(j);
                }
                else if(abs(nextT - nt) < EPS)
                {
                    Ri.add(i);
                    Rj.add(j);
                }
            }
        if(T + nextT > t + EPS) 
        {
            for(int i = 0; i < x.length; i++) x[i] += v[i] * (t - T);
            return;
        }
        if(Ri.size() > 0) 
        {
            for(int i = 0; i < x.length; i++) x[i] += v[i] * nextT;
            for(int i = 0; i < Ri.size(); i++)
            {
                int ri = Ri.get(i), rj = Rj.get(i);
                double vi = ((m[ri] - m[rj]) * v[ri] + 2 * m[rj] * v[rj]) / (m[ri] + m[rj]);
                double vj = ((m[rj] - m[ri]) * v[rj] + 2 * m[ri] * v[ri]) / (m[rj] + m[ri]);
                v[ri] = vi;
                v[rj] = vj;
            }
            simul(x, v, m, T + nextT, count + 1);
        }
    }
    
    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }
    
    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }
    
    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }
    
    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
    
    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }
    
    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }
    
    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;
    
    public static void main(String[] args) throws IOException
    {
        new Thread(null, new E(), "", 1 << 20).start();
    }
    
    public void run()
    {
        try
        {
            init();
            solve();
            out.close();        
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}