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 {
  double x;
  double v;
  int m;
  int idx;
};
bool nodeCmp(const struct Node &n1, const struct Node &n2) {
  return n1.x <= n2.x;
}
bool nodeCmp2(const struct Node &n1, const struct Node &n2) {
  return n1.idx <= n2.idx;
}
void calcV(Node &n1, Node &n2, double &nv1, double &nv2) {
  nv1 = ((n1.m - n2.m) * n1.v + 2 * n2.m * n2.v) / (n1.m + n2.m);
  nv2 = ((n2.m - n1.m) * n2.v + 2 * n1.m * n1.v) / (n1.m + n2.m);
}
bool collide(Node &n1, Node &n2, double &t, double &nv1, double &nv2) {
  double v = n1.v - n2.v;
  if (v <= 0) return false;
  t = (n2.x - n1.x) / v;
  if (t <= 1e-9) return false;
  nv1 = ((n1.m - n2.m) * n1.v + 2 * n2.m * n2.v) / (n1.m + n2.m);
  nv2 = ((n2.m - n1.m) * n2.v + 2 * n1.m * n1.v) / (n1.m + n2.m);
  return true;
}
int main(void) {
  int n, t;
  cin >> n >> t;
  vector<Node> nodes(n);
  int i, j;
  for (i = 0; i < n; ++i) {
    cin >> nodes[i].x >> nodes[i].v >> nodes[i].m;
    nodes[i].idx = i;
  }
  double cur = 0;
  while (1) {
    stable_sort(nodes.begin(), nodes.end(), nodeCmp);
    double minCollideTime = t + 1;
    vector<int> poses;
    for (i = 0; i < n - 1; ++i) {
      double collideTime;
      double v1, v2;
      bool ret = collide(nodes[i], nodes[i + 1], collideTime, v1, v2);
      if (ret) {
        if (collideTime + 1e-9 <= minCollideTime) {
          minCollideTime = collideTime;
          poses.clear();
          poses.push_back(i);
        } else if (collideTime > minCollideTime - 1e-9 &&
                   collideTime < minCollideTime + 1e-9) {
          poses.push_back(i);
        }
      }
    }
    if (poses.size() == 0) break;
    if (cur + minCollideTime > t) break;
    for (i = 0; i < n; ++i) {
      nodes[i].x += nodes[i].v * minCollideTime;
    }
    for (i = 0; i < poses.size(); ++i) {
      int j = poses[i];
      double v1, v2;
      calcV(nodes[j], nodes[j + 1], v1, v2);
      nodes[j].v = v1;
      nodes[j + 1].v = v2;
    }
    double aa = 1e-10;
    for (i = 0; i < n; ++i) {
      nodes[i].x += nodes[i].v * aa;
    }
    cur += minCollideTime + aa;
  }
  double rem = t - cur;
  sort(nodes.begin(), nodes.end(), nodeCmp2);
  for (i = 0; i < n; ++i) {
    printf("%.9f\n", nodes[i].x + rem * nodes[i].v);
  }
  return 0;
}