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;
int n, t, m[11], id[11];
double x[11], v[11], last[11], ans[11];
set<pair<double, pair<int, int>>> events;
double pos(int i, double t) { return x[i] + (t - last[i]) * v[i]; }
double toc(int i, int j) {
  double rvel = v[i] - v[j];
  if (rvel <= 0) return DBL_MAX;
  double t = max(last[i], last[j]);
  return t + (pos(j, t) - pos(i, t)) / rvel;
}
int main() {
  scanf("%d %d", &n, &t);
  vector<vector<int>> inp;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    inp.push_back({a, b, c, i});
  }
  sort(inp.begin(), inp.end());
  for (int i = 0; i < n; i++) {
    x[i] = inp[i][0], v[i] = inp[i][1], m[i] = inp[i][2], id[i] = inp[i][3];
    if (i) {
      double f = toc(i - 1, i);
      events.insert({f, {i - 1, i}});
    }
  }
  while (1) {
    pair<double, pair<int, int>> ev = *events.begin();
    if (ev.first >= t) break;
    events.erase(ev);
    double tt = ev.first;
    int i = ev.second.first, j = ev.second.second;
    if (i) {
      double f = toc(i - 1, i);
      events.erase({f, {i - 1, i}});
    }
    if (j + 1 < n) {
      double f = toc(j, j + 1);
      events.erase({f, {j, j + 1}});
    }
    double nv1, nv2;
    nv1 = ((m[i] - m[j]) * v[i] + 2 * m[j] * v[j]) / (m[i] + m[j]);
    nv2 = ((m[j] - m[i]) * v[j] + 2 * m[i] * v[i]) / (m[i] + m[j]);
    x[i] = x[j] = x[i] + (tt - last[i]) * v[i];
    last[i] = last[j] = tt;
    v[i] = nv1, v[j] = nv2;
    {
      double f = toc(i, j);
      events.insert({f, {i, j}});
    }
    if (i) {
      double f = toc(i - 1, i);
      events.insert({f, {i - 1, i}});
    }
    if (j + 1 < n) {
      double f = toc(j, j + 1);
      events.insert({f, {j, j + 1}});
    }
  }
  for (int i = 0; i < n; i++) {
    int j = inp[i][3];
    ans[j] = x[i] + (t - last[i]) * v[i];
  }
  for (int i = 0; i < n; i++) {
    printf("%.9f\n", ans[i]);
  }
  return 0;
}