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 ball {
  double v, m, x, t;
  int idx;
};
bool cmp(const ball& lhs, const ball& rhs) { return lhs.x < rhs.x; }
ball balls[16];
double colL[16], colR[16];
double ans[16];
int main() {
  int N, T;
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> balls[i].x >> balls[i].v >> balls[i].m;
    balls[i].t = 0;
    balls[i].idx = i;
  }
  sort(balls, balls + N, cmp);
  colL[0] = colR[N - 1] = -1;
  for (int i = 1; i < N; i++) {
    double sep = abs(balls[i - 1].x - balls[i].x);
    double vel = balls[i - 1].v - balls[i].v;
    if (vel <= 0)
      colR[i - 1] = colL[i] = -1;
    else
      colR[i - 1] = colL[i] = sep / vel;
  }
  set<tuple<double, int, int> > s;
  for (int i = 1; i < N; i++) {
    if (colL[i] != -1) s.insert(make_tuple(colL[i], i - 1, i));
  }
  while (s.size() != 0) {
    auto it = s.begin();
    if (get<0>(*it) > T) break;
    int b1 = get<1>(*it), b2 = get<2>(*it);
    double nv1 = ((balls[b1].m - balls[b2].m) * balls[b1].v +
                  2 * balls[b2].m * balls[b2].v) /
                 (balls[b1].m + balls[b2].m);
    double nv2 = ((balls[b2].m - balls[b1].m) * balls[b2].v +
                  2 * balls[b1].m * balls[b1].v) /
                 (balls[b1].m + balls[b2].m);
    balls[b1].x += balls[b1].v * (get<0>(*it) - balls[b1].t);
    balls[b2].x += balls[b2].v * (get<0>(*it) - balls[b2].t);
    balls[b1].t = balls[b2].t = get<0>(*it);
    balls[b1].v = nv1;
    balls[b2].v = nv2;
    s.erase(it);
    colR[b1] = -1;
    colL[b2] = -1;
    if (b1 != 0) {
      if (colL[b1] != -1) s.erase(s.find(make_tuple(colL[b1], b1 - 1, b1)));
      double sep =
          abs(balls[b1 - 1].x +
              balls[b1 - 1].v * (balls[b1].t - balls[b1 - 1].t) - balls[b1].x);
      double vel = balls[b1 - 1].v - balls[b1].v;
      if (vel <= 0)
        colR[b1 - 1] = colL[b1] = -1;
      else {
        colR[b1 - 1] = colL[b1] = balls[b1].t + (sep / vel);
        s.insert(make_tuple(colL[b1], b1 - 1, b1));
      }
    }
    if (b2 != N - 1) {
      if (colR[b2] != -1) s.erase(s.find(make_tuple(colR[b2], b2, b2 + 1)));
      double sep =
          abs(balls[b2 + 1].x +
              balls[b2 + 1].v * (balls[b2].t - balls[b2 + 1].t) - balls[b2].x);
      double vel = balls[b2].v - balls[b2 + 1].v;
      if (vel <= 0)
        colR[b2] = colL[b2 + 1] = -1;
      else {
        colR[b2] = colL[b2 + 1] = balls[b2].t + (sep / vel);
        s.insert(make_tuple(colR[b2], b2, b2 + 1));
      }
    }
  }
  for (int i = 0; i < N; i++)
    ans[balls[i].idx] = balls[i].x + balls[i].v * (T - balls[i].t);
  for (int i = 0; i < N; i++) printf("%0.9lf\n", ans[i]);
  return 0;
}