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 <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
using pll = pair<long double, long double>;
void xmax(long long& a, long long b) { a = max(a, b); }
void xmin(long double& a, long double b) { a = min(a, b); }
void print(vc<long long>& a, string second) {
  cerr << "prinitng " << second << "\n";
  for (long long i = 0; i < a.size(); i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;
}
vc<long double> w;
vc<long double> x;
vc<long double> v;
long double eps = 1e-12;
long long n;
long double t;
vc<pair<pll, pll> > a;
long double coll(long double x1, long double v1, long double x2,
                 long double v2) {
  if (v2 >= v1) return t + 7;
  long double dx = x2 - x1;
  long double b;
  b = v2 * dx / (v1 - v2);
  if (v2 != 0)
    return b / v2;
  else
    return (dx + b) / v1;
}
void do_collision(long long ind) {
  long double v1 = a[ind].first.second;
  long double v2 = a[ind + 1].first.second;
  assert(v2 < v1);
  long double dx = a[ind + 1].first.first - a[ind].first.first;
  long double b = v2 * dx / (v1 - v2);
  long double m1 = a[ind].second.first;
  long double m2 = a[ind + 1].second.first;
  a[ind].first.first = b + a[ind + 1].first.first;
  a[ind + 1].first.first += b;
  a[ind].first.second = ((m1 - m2) * v1 + 2 * m2 * v2) / (m1 + m2);
  a[ind + 1].first.second = ((m2 - m1) * v2 + 2 * m1 * v1) / (m1 + m2);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> t;
  vc<long double> w(n);
  vc<long double> x(n);
  vc<long double> v(n);
  a = vc<pair<pll, pll> >(n);
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i] >> w[i];
    a[i] = {{x[i], v[i]}, {w[i], i}};
  }
  sort(a.begin(), a.end());
  long double cur_time = 0;
  while (true) {
    long double next = t - cur_time;
    vc<long double> times(n - 1);
    for (long long i = 0; i + 1 < n; i++) {
      times[i] = coll(a[i].first.first, a[i].first.second, a[i + 1].first.first,
                      a[i + 1].first.second);
      xmin(next, times[i]);
    }
    vc<long long> changed(n);
    for (long long i = 0; i + 1 < n; i++) {
      if (abs(times[i] - next) < eps) {
        changed[i] = 1;
        changed[i + 1] = 1;
        do_collision(i);
      }
    }
    for (long long i = 0; i < n; i++) {
      if (!changed[i]) a[i].first.first += next * a[i].first.second;
    }
    cur_time += next;
    if (abs(cur_time - t) < eps) break;
  }
  vc<long double> wo(n);
  for (long long i = 0; i < n; i++) {
    wo[a[i].second.second] = a[i].first.first;
  }
  for (long long i = 0; i < n; i++) {
    cout << setprecision(10) << wo[i] << "\n";
  }
  cerr << "end case \n\n";
}