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>
#pragma GCC optimize("O2")
using namespace std;
int n, t;
struct arr {
  double x, s, w;
  int p;
};
arr v[12];
bool cmp(arr a, arr b) { return a.x < b.x; }
bool cmp2(arr a, arr b) { return a.p < b.p; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> t;
  double t2 = 0.0 + t;
  for (int i = 1; i <= n; ++i) {
    int x, s, w;
    cin >> x >> s >> w;
    v[i] = {0.0 + x, 0.0 + s, 0.0 + w};
    v[i].p = i;
  }
  sort(v + 1, v + n + 1, cmp);
  double tt = 0.0;
  int ps = 0;
  int lca = 0, lcb = 0;
  while (tt < t2) {
    ++ps;
    double mint = 102.00;
    int x = 0, y = 0;
    for (int i = 1; i < n; ++i) {
      if (v[i].x == v[i + 1].x) continue;
      if (v[i].s > 0 && v[i + 1].s > 0) {
        double ttt = (v[i + 1].x - v[i].x) / (v[i].s - v[i + 1].s);
        if (ttt > 0.00 && ttt < mint) mint = ttt, x = i, y = i + 1;
      }
      if (v[i].s < 0 && v[i + 1].s < 0) {
        double ttt = (v[i + 1].x - v[i].x) / (v[i].s - v[i + 1].s);
        if (ttt > 0.00 && ttt < mint) mint = ttt, x = i, y = i + 1;
      }
      if (v[i].s > 0.0 && v[i + 1].s < 0.0) {
        double ttt = (v[i + 1].x - v[i].x) / (v[i].s - v[i + 1].s);
        if (ttt > 0.00 && ttt < mint) mint = ttt, x = i, y = i + 1;
      }
    }
    if (tt + mint >= t) mint = t - tt;
    for (int i = 1; i <= n; ++i) v[i].x += v[i].s * mint;
    for (int i = 1; i < n; ++i) {
      if (v[i].x == v[i + 1].x) {
        x = i, y = i + 1;
        double v1 = v[x].s;
        double v2 = v[y].s;
        v[x].s = ((v[x].w - v[y].w) * v1 + 2.0000 * v[y].w * v2) /
                 (0.00 + v[x].w + v[y].w);
        v[y].s = ((v[y].w - v[x].w) * v2 + 2.0000 * v[x].w * v1) /
                 (0.00 + v[x].w + v[y].w);
      }
    }
    lca = x, lcb = y;
    tt += mint;
  }
  sort(v + 1, v + n + 1, cmp2);
  for (int i = 1; i <= n; ++i)
    cout << fixed << setprecision(12) << v[i].x << '\n';
  return 0;
}