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;
template <class first, class T>
T convert(first a, int p = -1) {
  stringstream ss;
  if (p >= 0) ss << fixed << setprecision(p);
  ss << a;
  T r;
  ss >> r;
  return r;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T cube(T x) {
  return x * x * x;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
const long double PI = acos(-1.0);
const long double EPS = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int INF = (int)1e9 + 5;
const long long LINF = (long long)1e16 + 5;
const long long MOD = (long long)1e9 + 7;
class Ball {
 public:
  double x, v, m;
  Ball() {}
  Ball(double _x, double _v, double _m) {
    x = _x;
    v = _v;
    m = _m;
  }
};
int N;
double T;
vector<Ball> ball;
vector<vector<double> > tcol;
void touch(Ball &a, Ball &b) {
  double v1 = a.v, v2 = b.v;
  double m1 = a.m, m2 = b.m;
  a.v = ((m1 - m2) * v1 + 2 * m2 * v2) / (m1 + m2);
  b.v = ((m2 - m1) * v2 + 2 * m1 * v1) / (m1 + m2);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> T;
  for (int i = 0; i < (N); ++i) {
    double _x, _v, _m;
    cin >> _x >> _v >> _m;
    ball.push_back(Ball(_x, _v, _m));
  }
  tcol.assign(N, vector<double>(N));
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (i); ++j) {
      if (ball[i].v != ball[j].v)
        tcol[i][j] = (ball[i].x - ball[j].x) / (ball[j].v - ball[i].v);
      else
        tcol[i][j] = INF;
    }
  }
  double t = 0.0;
  while (t < T) {
    T -= t;
    for (int i = 0; i < (N); ++i) ball[i].x += ball[i].v * t;
    for (int i = 0; i < (N); ++i)
      for (int j = 0; j < (i); ++j)
        if (tcol[i][j] == t) touch(ball[i], ball[j]);
    for (int i = 0; i < (N); ++i)
      for (int j = 0; j < (i); ++j)
        if (ball[i].v != ball[j].v)
          tcol[i][j] = (ball[i].x - ball[j].x) / (ball[j].v - ball[i].v);
        else
          tcol[i][j] = INF;
    t = INF;
    for (int i = 0; i < (N); ++i)
      for (int j = 0; j < (i); ++j)
        if (tcol[i][j] > EPS) t = min(t, tcol[i][j]);
  }
  for (int i = 0; i < (N); ++i) ball[i].x += ball[i].v * T;
  for (int i = 0; i < (N); ++i) cout << setprecision(12) << ball[i].x << "\n";
}