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;
const int MAXN = 120;
int n, t;
struct Node {
  double v, x, m;
  int id;
  void input() { scanf("%lf%lf%lf", &x, &v, &m); }
};
inline void change(Node &n1, Node &n2) {
  double a, b;
  a = ((n1.m - n2.m) * n1.v + 2 * n2.m * n2.v) / (n1.m + n2.m);
  b = ((n2.m - n1.m) * n2.v + 2 * n1.m * n1.v) / (n1.m + n2.m);
  n1.v = a;
  n2.v = b;
}
inline int cmp(Node a, Node b) { return a.x + 1e-18 < b.x; }
Node nodes[MAXN];
inline double solve(Node p1, Node p2) {
  double t = 1e99;
  if (fabs(p1.v) < 1e-18) {
    if (p2.v < -1e-18) {
      t = (p2.x - p1.x) / fabs(p2.v);
    }
    return t;
  }
  if (fabs(p2.v) < 1e-18) {
    if (p1.v > 1e-18) {
      t = (p2.x - p1.x) / p1.v;
    }
    return t;
  }
  if (p1.v * p2.v > 1e-18) {
    if (p1.v > 1e-18) {
      if (p1.v - p2.v > 1e-18) {
        t = ((t) > ((p2.x - p1.x) / (p1.v - p2.v))
                 ? ((p2.x - p1.x) / (p1.v - p2.v))
                 : (t));
      }
    } else {
      if (fabs(p2.v) > fabs(p1.v) + 1e-18) {
        t = ((t) > ((p2.x - p1.x) / (fabs(p2.v) - fabs(p1.v)))
                 ? ((p2.x - p1.x) / (fabs(p2.v) - fabs(p1.v)))
                 : (t));
      }
    }
  } else {
    if (p1.v > 1e-18 && p2.v < -1e-18) {
      t = ((t) > ((p2.x - p1.x) / (p1.v - p2.v))
               ? ((p2.x - p1.x) / (p1.v - p2.v))
               : (t));
    }
  }
  return t;
}
inline int cmp1(Node a, Node b) { return a.id < b.id; }
int main() {
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i) {
    nodes[i].input();
    nodes[i].id = i;
  }
  sort(nodes, nodes + n, cmp);
  double ts, curt, curx, tmp, tt;
  int u;
  ts = 0;
  while (ts + 1e-18 < (double)t) {
    tt = (double)t - ts;
    u = 0;
    curt = 1e99;
    for (int i = 0; i < n - 1; ++i) {
      double tg = solve(nodes[i], nodes[i + 1]);
      if (curt > tg + 1e-18) {
        curt = tg;
        u = i;
      }
    }
    ts += curt;
    if (curt >= tt) continue;
    tt = tt - curt;
    for (int i = 0; i < n; ++i) {
      nodes[i].x = nodes[i].x + nodes[i].v * curt;
    }
    change(nodes[u], nodes[u + 1]);
  }
  for (int i = 0; i < n; ++i) {
    nodes[i].x = nodes[i].x + nodes[i].v * tt;
  }
  sort(nodes, nodes + n, cmp1);
  for (int i = 0; i < n; ++i) {
    printf("%.9lf\n", nodes[i].x);
  }
  return 0;
}