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;
double min(double a, double b) { return a < b ? a : b; }
int n;
struct pl {
  int idx;
  double x, v, m;
} p[12], tp[12];
int eq(double a, double b) {
  if (fabs(a - b) < 1e-7)
    return 1;
  else
    return 0;
}
double get() {
  int i;
  double ret = -1;
  double t, x;
  for (i = 0; i < n - 1; i++) {
    if (p[i].v > p[i + 1].v) {
      t = (p[i].x - p[i + 1].x) / (p[i + 1].v - p[i].v);
      if (ret == -1)
        ret = t;
      else
        ret = min(ret, t);
    }
  }
  return ret;
}
int mark[12];
void done(double t) {
  int i;
  for (i = 0; i < n; i++) mark[i] = 0;
  for (i = 0; i < n; i++) {
    tp[i].x = p[i].x + p[i].v * t;
    tp[i].m = p[i].m;
    tp[i].idx = p[i].idx;
  }
  for (i = 0; i < n - 1; i++) {
    if (!mark[i]) {
      if (eq(tp[i].x, tp[i + 1].x)) {
        mark[i] = 1;
        mark[i + 1] = 1;
        tp[i].v =
            ((p[i].m - p[i + 1].m) * p[i].v + 2 * p[i + 1].m * p[i + 1].v) /
            (p[i].m + p[i + 1].m);
        tp[i + 1].v =
            ((p[i + 1].m - p[i].m) * p[i + 1].v + 2 * p[i].m * p[i].v) /
            (p[i].m + p[i + 1].m);
      } else {
        mark[i] = 1;
        tp[i].v = p[i].v;
      }
    }
  }
  if (!mark[i]) {
    mark[i] = 1;
    tp[i].v = p[i].v;
  }
  for (i = 0; i < n; i++) {
    p[i] = tp[i];
  }
}
int cmp(pl a, pl b) { return a.x < b.x; }
int cmpp(pl a, pl b) { return a.idx < b.idx; }
int main() {
  int i, j, r1, r2, k;
  double t;
  while (scanf("%d %lf", &n, &t) == 2) {
    for (i = 0; i < n; i++) {
      scanf("%lf %lf %lf", &p[i].x, &p[i].v, &p[i].m);
      p[i].idx = i;
    }
    sort(p, p + n, cmp);
    if (n == 1) {
      printf("%lf\n", p[0].x + (p[0].v) * t);
      continue;
    }
    double nt = 0, thent;
    while (nt < t) {
      thent = get();
      if (thent == -1) {
        done(t - nt);
        nt = t + 1;
      } else {
        if ((nt + thent) < t) {
          done(thent);
          nt += thent;
        } else {
          done(t - nt);
          nt = t + 1;
        }
      }
    }
    sort(p, p + n, cmpp);
    for (i = 0; i < n; i++) {
      printf("%.9lf\n", p[i].x);
    }
  }
}