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.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.reverse;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.geom.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class E {
//    static final double MAX= 1000000000;
    static final double MAX= Double.MAX_VALUE/2;

    /*
     * !!! simulate n point movement on line
     * 
     * t=0
     * ball i: coordinate xi, speed vi (possibly, negative) and weight mi
     * 
     * find out where each ball will be t seconds after
     * 
     * three or more balls never collide at the same point in all times from segment [0;t]
     */
    void solve() throws Exception {
        int n = INT();
        int t = INT();
        Obj[] obj = new Obj[n];
        for (int i = 0; i < n; i++) {
            obj[i]=new Obj(i, INT(),INT(),INT());
        }
        sort(obj);
        double prev=0;
        while(true) {
            double nxt=collide(obj);
            if (prev+nxt>=t) {
                break;
            }
            update(obj,nxt);
            prev+=nxt;
        }
        update(obj,t-prev);
        
        sort(obj, new Comparator<Obj>() {
            @Override
            public int compare(Obj o1, Obj o2) {
                // < : -1 smallest 1st
                // > : -1 biggest 1st
                return (o1.idx < o2.idx ? -1 : (o1.idx == o2.idx ? 0 : 1));
            }
        });
        for (int i = 0; i < obj.length; i++) {
            System.out.println(obj[i].x);
        }
    }
    
    private void update(Obj[] obj, double past) {
        for (int i = 0; i < obj.length; i++) {
            obj[i].x+=obj[i].v*past;
        }
        for (int i = 1; i < obj.length; i++) {
            if (abs(obj[i].x-obj[i-1].x)<=1e-8) {
                // collide
                double v1 = obj[i-1].v, v2 = obj[i].v; 
                double m1 = obj[i-1].m, m2 = obj[i].m;
                double v11=((m1-m2)*v1+2*m2*v2)/(m1+m2);
                double v22=((m2-m1)*v2+2*m1*v1)/(m1+m2);
                obj[i-1].v=v11;
                obj[i].v=v22;
                if (obj[i].x!=obj[i-1].x) {
                    obj[i].x=obj[i-1].x=(obj[i].x+obj[i-1].x)/2;
                }
            }
        }
    }

    private double collide(Obj[] obj) {
        double t=MAX;
        for (int i = 1; i < obj.length; i++) {
            double v=time(obj[i-1],obj[i]);
            t = Math.min(t, v);
        }
        return t;
    }

    private double time(Obj o1, Obj o2) {
        double dx=o2.x-o1.x;
        double dv=o1.v-o2.v;
        if (dv<=0) {
            return MAX;
        }
        return dx/dv;
    }

    class Obj implements Comparable<Obj> {
        int idx;
        double x,v,m;

        public Obj(int idx, double x, double v, double m) {
            super();
            this.idx = idx;
            this.x = x;
            this.v = v;
            this.m = m;
        }

        public String toString() {
            return "[x=" + x + ", v=" + v + ", m=" + m + "]";
        }

        @Override
        public int compareTo(Obj o) {
            // < : -1 smallest 1st
            // > : -1 biggest 1st
            if (this.x==o.x) {
                return (this.v < o.v ? -1 : (this.v == o.v ? 0 : 1));
            }
            return (this.x < o.x ? -1 : (this.x == o.x ? 0 : 1));
        }
        
    }
    
    public static void main(String[] args) throws Exception {
        boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
        boolean localTest = !onlineJudge && new File(testFilename).exists();
        long start = System.currentTimeMillis();

        if(!onlineJudge && redirectStdoutToFile) {
            String filename = "output.txt";
            System.out.println("NOTE: redirect stdout to file "+filename);
            System.setOut(new PrintStream(new FileOutputStream(filename),true));
        }

        if (!localTest) {
            in = new BufferedReader(new InputStreamReader(System.in));
            new E().solve();
        } else {
            in = new BufferedReader(new FileReader(testFilename));
            while(true) {
                new E().solve();
                if (LINE() == null) {
                    break;
                }
                System.out.println();
            }
        }

        if(!onlineJudge) System.out.println("\nTime taken: "+((System.currentTimeMillis()-start)/1000.0)+" sec");
    }

    static boolean printInput=false;
//    static boolean printInput=true; // print input case
  
    static boolean redirectStdoutToFile=false;
//    static boolean redirectStdoutToFile=true; // redirect all STDOUT to "output.txt"

    static String testFilename="e-test-in.txt";
  
    static BufferedReader in;
    static StringTokenizer inTok = new StringTokenizer("");

    static String LINE() throws IOException {
        String s=in.readLine();
        if (printInput) System.out.println(s);
        return s;
    }
    static String STR() throws IOException {
        while (!inTok.hasMoreTokens()) {
            String line = LINE();
            if (line == null) {
                return null;
            }
            inTok = new StringTokenizer(line);
        }
        return inTok.nextToken();
    }
    static int INT() throws IOException { return Integer.parseInt(STR()); }
    static long LONG() throws IOException { return Long.parseLong(STR()); }
    static double DOUBLE() throws IOException { return Double.parseDouble(STR()); }
}