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 warning(disable : 4996)
static const double eps = 1.0e-10;
inline void DoNothing() {}
template <typename T>
inline T Abs(const T a) {
  return a < 0 ? -a : a;
}
template <typename T>
inline T Min(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T Max(const T a, const T b) {
  return a > b ? a : b;
}
inline double IsEqual(const double a, const double b) {
  return Abs(a - b) < eps;
}
inline double IsGreater(const double a, const double b) { return a > b + eps; }
inline double IsLess(const double a, const double b) { return a + eps < b; }
struct Rand {
  unsigned long z_, w_;
  unsigned long get32() {
    z_ = 36969 * (z_ & 65535) + (z_ >> 16);
    w_ = 18000 * (w_ & 65535) + (w_ >> 16);
    return (z_ << 16) + (w_ & 65535);
  }
  void Reset() {
    z_ = 1;
    w_ = 1;
  }
  Rand() { Reset(); }
};
class StopWatch {
 public:
  StopWatch(const char*) {}
};
struct Ball {
  size_t id;
  double x;
  double v;
  double m;
  Ball(size_t id_, double x_, double v_, double m_)
      : id(id_), x(x_), v(v_), m(m_) {}
};
bool IsLessX(const Ball& b1, const Ball& b2) { return b1.x < b2.x; }
bool IsLessId(const Ball& b1, const Ball& b2) { return b1.id < b2.id; }
static const double MAX_TIME = 2000.0;
double GetMeetTime(const Ball& b1, const Ball& b2) {
  if (!IsEqual(b1.v, b2.v) && !IsEqual(b1.x, b2.x)) {
    const double t = (b1.x - b2.x) / (b2.v - b1.v);
    return IsLess(t, 0) ? MAX_TIME : t;
  }
  { return MAX_TIME; }
}
void Knock(Ball& b1, Ball& b2) {
  if (IsEqual(b1.x, b2.x)) {
    const double v1 = ((b1.m - b2.m) * b1.v + 2 * b2.m * b2.v) / (b1.m + b2.m);
    const double v2 = ((b2.m - b1.m) * b2.v + 2 * b1.m * b1.v) / (b1.m + b2.m);
    b1.v = v1;
    b2.v = v2;
  }
}
void Move(Ball& b, const double dt) { b.x += b.v * dt; }
int main() {
  StopWatch sw("whole");
  std::istream& ifs = std::cin;
  std::ostream& ofs = std::cout;
  size_t n;
  double tEnd;
  ifs >> n >> tEnd;
  std::vector<Ball> balls;
  for (size_t i = 0; i < n; i++) {
    double x, v, m;
    ifs >> x >> v >> m;
    balls.push_back(Ball(i + 1, x, v, m));
  }
  std::sort(balls.begin(), balls.end(), &IsLessX);
  double tCur = 0;
  while (IsLess(tCur, tEnd)) {
    const double tPrev = tCur;
    bool bFound = false;
    double dtMin = MAX_TIME;
    for (size_t i = 0; i < n - 1; i++) {
      const double tMeet = GetMeetTime(balls[i], balls[i + 1]);
      if (tMeet + tPrev < tEnd && (!bFound || tMeet < dtMin)) {
        dtMin = tMeet;
        bFound = true;
      }
    }
    if (!bFound) {
      dtMin = tEnd - tPrev;
    }
    for (size_t i = 0; i < n; i++) {
      Move(balls[i], dtMin);
    }
    for (size_t i = 0; i < n - 1; i++) {
      Knock(balls[i], balls[i + 1]);
    }
    tCur = tPrev + dtMin;
  }
  std::sort(balls.begin(), balls.end(), &IsLessId);
  for (size_t i = 0; i < n; i++) {
    ofs << std::setprecision(11) << balls[i].x << std::endl;
  }
}