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 inf = 1000 * 1000 * 1000;
const long long inf64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
class ball {
 public:
  long double x, v, m, i;
};
vector<ball> v;
int n, T;
void Load() {
  cin >> n >> T;
  ball cur;
  for (int i = 0; i < n; i++) {
    cin >> cur.x >> cur.v >> cur.m;
    cur.i = i;
    v.push_back(cur);
  }
}
bool operator<(const ball &a, const ball &b) {
  return a.x < b.x - 1e-9 || (fabs(a.x - b.x) < 1e-9 && a.v < b.v - 1e-9);
}
void Solve() {
  cerr.setf(ios::fixed | ios::showpoint);
  cerr.precision(10);
  long double t, nxt_t, cur_t;
  t = 0;
  sort(v.begin(), v.end());
  while (true) {
    nxt_t = inf;
    for (int i = 0; i < n - 1; i++) {
      if (fabs(v[i].v - v[i + 1].v) < 1e-9) continue;
      cur_t = (v[i + 1].x - v[i].x) / (v[i].v - v[i + 1].v);
      if (cur_t < 1e-9) continue;
      nxt_t = min(nxt_t, cur_t);
    }
    if (t + nxt_t > T + 1e-9) {
      for (int i = 0; i < n; i++) v[i].x = v[i].x + v[i].v * (T - t);
      break;
    }
    t = t + nxt_t;
    for (int i = 0; i < n; i++) v[i].x = v[i].x + v[i].v * nxt_t;
    for (int i = 0; i < n - 1; i++)
      if (fabs(v[i].x - v[i + 1].x) < 1e-9) {
        long double v1, v2;
        v1 = ((v[i].m - v[i + 1].m) * v[i].v + 2 * v[i + 1].m * v[i + 1].v) /
             (v[i].m + v[i + 1].m);
        v2 = ((v[i + 1].m - v[i].m) * v[i + 1].v + 2 * v[i].m * v[i].v) /
             (v[i].m + v[i + 1].m);
        v[i].v = v1;
        v[i + 1].v = v2;
      }
    sort(v.begin(), v.end());
  }
  cout.setf(ios::fixed | ios::showpoint);
  cout.precision(10);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (v[j].i == i) cout << v[j].x << "\n";
}
int main() {
  Load();
  Solve();
  return 0;
}