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.math.*;
import java.util.*;
import java.util.concurrent.*;

public class P34E {

  final static double EPS = 1.0E-9;

  double [] x, v, m;

  int cmp(double a, double b) {
    return ((Math.abs(a - b) < EPS) ? 0 : ((a < b) ? -1 : 1));
  }

  double v1(int i, int j) {
    return (((m[i] - m[j]) * v[i] + 2 * m[j] * v[j]) / (m[i] + m[j]));
  }

  double v2(int i, int j) {
    return (((m[j] - m[i]) * v[j] + 2 * m[i] * v[i]) / (m[i] + m[j]));
  }

  double dt(int i, int j) {
    double dt = (x[i] - x[j]) / (v[j] - v[i]);
    return ((Double.isNaN(dt) || Double.isInfinite(dt) || (cmp(dt, 0.0) <= 0)) ? Double.POSITIVE_INFINITY : dt);
  }


  @SuppressWarnings("unchecked")
  public void run() throws Exception {
    int n = nextInt();
    x = new double[n];
    v = new double[n];
    m = new double[n];
    double t = 0;
    double finT = nextDouble();
    for (int i = 0; i < n; i++) {
      x[i] = nextDouble();
      v[i] = nextDouble();
      m[i] = nextDouble();
    }
    double [][] dtij = new double [n * (n - 1) / 2][3];

    while (cmp(t, finT) < 0) {
      double minDT = finT - t;
      int idx = 0;

      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          dtij[idx][0] = dt(i, j);
          dtij[idx][1] = i;
          dtij[idx][2] = j;
          minDT = Math.min(minDT, dtij[idx][0]);
          idx++;
        }
      }

      for (int i = 0; i < n; i++) {
        x[i] += v[i] * minDT;
      }

      for (int k = 0; k < dtij.length; k++) {
        if (cmp(minDT, dtij[k][0]) == 0) {
System.err.println("[Collision at [" + (t + minDT) + "] with " + (int)(dtij[k][1] + 1) + " and " + (int)(dtij[k][2] + 1) + "]");
          int i = (int)dtij[k][1];
          int j = (int)dtij[k][2];
          double v1 = v1(i, j);
          double v2 = v2(i, j);
          v[i] = v1;
          v[j] = v2;
        }
      }
      
      t += minDT;
    }

    for (double xx : x) {
      println(xx);
    }
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P34E().run();
    br.close();
    pw.close();
  }

  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }
}