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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct node {
  int ith;
  double p;
  double v;
  double m;
  double tc;
  bool operator<(const node& A) const { return A.p > p; }
} init[15];
int order[15];
int collid[15];
const double INF = 1e-9;
int main() {
  int n, i, x, v, m, k, a1, a2, flag, num;
  double t0, aa, bb, xx, yy, t1, dd, tt, v1, v2, m1, m2, t;
  while (scanf("%d%lf", &n, &t) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%lf%lf%lf", &init[i].p, &init[i].v, &init[i].m);
      init[i].ith = i;
      init[i].tc = 10000.0;
    }
    sort(init, init + n);
    for (i = 0; i < n; i++) {
      order[init[i].ith] = i;
    }
    if (n == 1) {
      init[0].p = init[0].p + init[0].v * t;
    } else {
      while (t > 0) {
        t0 = t;
        flag = 0;
        for (i = 0; i < n - 1; i++) {
          xx = init[i].p;
          yy = init[i + 1].p;
          v1 = init[i].v;
          v2 = init[i + 1].v;
          if (v1 > v2) {
            dd = yy - xx;
            t1 = dd / (v1 - v2);
            if (t1 < t0) {
              flag = 1;
              t0 = t1;
              init[i].tc = t1;
            }
          }
        }
        if (flag) {
          for (i = 0; i < n; i++) {
            xx = init[i].p;
            v1 = init[i].v;
            init[i].p = xx + v1 * t0;
          }
          for (i = 0; i < n - 1;) {
            if (fabs(init[i].tc - t0) < INF) {
              a1 = i;
              a2 = i + 1;
              v1 = init[a1].v;
              v2 = init[a2].v;
              m1 = init[a1].m;
              m2 = init[a2].m;
              init[a1].v = ((m1 - m2) * v1 * 1.0 + 2 * m2 * v2) / (m1 + m2);
              init[a2].v = ((m2 - m1) * v2 * 1.0 + 2 * m1 * v1) / (m1 + m2);
              i += 2;
            } else
              i++;
          }
          for (i = 0; i < n; i++) init[i].tc = 10000.0;
          t -= t0;
        } else
          break;
      }
      if (!flag) {
        t0 = t;
        for (i = 0; i < n; i++) {
          xx = init[i].p;
          v1 = init[i].v;
          init[i].p = xx + v1 * t0;
        }
      }
    }
    for (i = 0; i < n; i++) {
      k = order[i];
      printf("%.9lf\n", init[k].p);
    }
  }
  return 0;
}