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.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";
            
            int n,t;
            Ball[] b;
            
            double cur=0;
            
            void check() {
                double min = Double.MAX_VALUE;
                
                for(int i = 0; i < n-1; ++i)
                    min = Math.min(time2boom(i,i+1),min);
                
                if(Double.compare(min, Double.MAX_VALUE)==0)
                    min = 0;
                
                min = Math.min(t-cur, min);
                
                for(int i = 0; i < n; ++i)
                    b[i].x += b[i].v*min;
                
                check_boom();
                cur += min;
            }
            
            double time2boom(int b1, int b2) {
                double v = b[b1].v-b[b2].v;
                if(v <= 0)
                    return Integer.MAX_VALUE;
                
                return (b[b2].x-b[b1].x)/v; 
            }
            
            void check_boom() {
                for(int i = 0; i < n-1; ++i)
                    if(b[i].x==b[i+1].x)
                        reflect(i,i+1);
            }
            
            void reflect(int b1, int b2) {
                int m1 = b[b1].m;
                int m2 = b[b2].m;
                
                double v1 = b[b1].v;
                double v2 = b[b2].v;
                
                b[b1].v = ((m1-m2)*v1+2*m2*v2)/(m1+m2);
                b[b2].v = ((m2-m1)*v2+2*m1*v1)/(m1+m2);
            }
            
            @Override
            public void run() {
                n = nextInt();
                t = nextInt();
                b = new Ball[n];
                
                for(int i = 0; i < n; ++i)
                    b[i] = new Ball(nextInt(),nextInt(),nextInt(),i);
                
                Arrays.sort(b);
                
                while(Double.compare(cur, t)<0)
                    check();
                
                Arrays.sort(b, new BComparator());
                
                for(Ball b1:b)
                    print(b1.x+"\n");
                close();
            }
            
            class BComparator implements Comparator<Ball> {
                @Override
                public int compare(Ball b1, Ball b2) {
                    return (new Integer(b1.num)).compareTo(b2.num);
                }
            }
            
            class Ball implements Comparable<Ball>{
                double x;
                double v;
                int m;
                int num;
                
                Ball(double x,double v,int m,int num) {
                    this.x = x;
                    this.v = v;
                    this.m = m;
                    this.num = num;
                }

                @Override
                public int compareTo(Ball b) {
                    return Double.compare(x, b.x);
                }
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;
           
            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }
           
            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
           
            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
           
            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
           
            int nextInt() {
                return Integer.parseInt(nextToken());
            }
           
            double nextDouble() {
                return Double.parseDouble(nextToken());
            }
           
            float nextFloat() {
                return Float.parseFloat(nextToken());
            }
           
            long nextLong() {
                return Long.parseLong(nextToken());
            }
           
            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }
           
            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }
           
            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
               
                return strTok.nextToken();
            }
           
            void cout(Object o){
                System.out.println(o);
            }
           
            void print(Object o) {
                out.write(o.toString());
            }
            
            void println(Object o) {
                out.write(o.toString() + '\n');
            }
           
            void printf(String format, Object... args) {
                out.printf(format, args);
            }
           
            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }
       
        static class Pair<A, B> {
            A a;
            B b;
           
            A f() {
                return a;
            }
           
            B s() {
                return b;
            }
           
            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }
           
            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }
       
        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }