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 x;
  double v;
  double m;
  double time;
  ball() {}
  ball(double x_, double v_, double m_, double t_)
      : x(x_), v(v_), m(m_), time(t_) {}
};
struct boom {
  int b1;
  int b2;
  double time;
  boom() {}
  boom(int b1_, int b2_, double time_) : b1(b1_), b2(b2_), time(time_) {}
};
int n;
double t;
double world_time = 0;
vector<ball> world;
stringstream dbg;
bool boom_was() {
  dbg << t << " WORLD TIME " << world_time << endl;
  vector<boom> booms(1, boom(-1, -1, t + 1));
  vector<vector<bool> > used(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      ball b1 = world[i];
      ball b2 = world[j];
      if (b1.v == b2.v || b1.x == b2.x || (b2.x - b1.x) / (b1.v - b2.v) <= 0)
        continue;
      double boom_time = world_time + (b2.x - b1.x) / (b1.v - b2.v);
      if (!used[i][j] && boom_time <= t && boom_time <= booms[0].time) {
        used[i][j] = true;
        used[j][i] = true;
        if (boom_time < booms[0].time) booms.clear();
        booms.push_back(boom(i, j, boom_time));
        dbg << "BOOM " << i << " in " << b1.x << " and " << j << " in " << b2.x
            << " time " << boom_time << " local_time "
            << (b2.x - b1.x) / (b1.v - b2.v) << endl;
      }
    }
  if (booms[0].b1 < 0) return false;
  vector<bool> boomers(n, true);
  double l_boom_time = 0;
  for (int i = 0; i < booms.size(); i++) {
    boomers[booms[i].b1] = false;
    boomers[booms[i].b2] = false;
    dbg << "boom bitween " << booms[i].b1 << " and " << booms[i].b2
        << " at time " << booms[i].time << endl;
    l_boom_time = booms[i].time - world_time;
    ball b1 = world[booms[i].b1];
    ball b2 = world[booms[i].b2];
    world[booms[i].b1].v =
        ((b1.m - b2.m) * b1.v + 2 * b2.m * b2.v) / (b1.m + b2.m);
    world[booms[i].b2].v =
        ((b2.m - b1.m) * b2.v + 2 * b1.m * b1.v) / (b1.m + b2.m);
    world[booms[i].b1].x = world[booms[i].b2].x = b1.x + b1.v * l_boom_time;
  }
  for (int i = 0; i < n; i++)
    if (boomers[i]) world[i].x = world[i].x + world[i].v * l_boom_time;
  dbg << "WORLD STATE NOW:" << endl;
  for (int i = 0; i < n; i++)
    dbg << i + 1 << " x=" << world[i].x << ", v=" << world[i].v << endl;
  world_time = booms[0].time;
  return true;
}
int main() {
  cin >> n >> t;
  world = vector<ball>(n, ball(0, 0, 0, t));
  for (int i = 0; i < n; i++) cin >> world[i].x >> world[i].v >> world[i].m;
  while (boom_was()) {
  }
  for (int i = 0; i < n; i++)
    cout << (world[i].x + world[i].v * (t - world_time)) << endl;
  return 0;
}