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 T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
int iter = 100;
using namespace std;
long double eps = 1e-9;
pair<long double, int> getT(vector<long double>& x, vector<long double>& v) {
  long double huh = 1e9, ind = -1;
  for (int i = 0; i < x.size() - 1; i++) {
    if (v[i] > v[i + 1] + eps) {
      if ((x[i + 1] - x[i]) / (v[i] - v[i + 1]) < huh) {
        huh = (x[i + 1] - x[i]) / (v[i] - v[i + 1]), ind = i;
      }
    }
  }
  return {huh, ind};
}
pair<long double, long double> getV(long double m1, long double v1,
                                    long double m2, long double v2) {
  long double vr1 = ((m1 - m2) * v1 + 2 * m2 * v2) / (m1 + m2);
  long double vr2 = ((m2 - m1) * v2 + 2 * m1 * v1) / (m1 + m2);
  return {vr1, vr2};
}
struct E {
  long double x, v, m;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  long double t;
  cin >> n >> t;
  vector<E> event(n);
  vector<long double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> event[i].x >> event[i].v >> event[i].m;
    p[i] = i;
  }
  sort(p.begin(), p.end(),
       [&](int i, int j) { return event[i].x < event[j].x; });
  vector<long double> v(n), x(n), m(n);
  for (int i = 0; i < n; i++) {
    v[i] = event[p[i]].v;
    x[i] = event[p[i]].x;
    m[i] = event[p[i]].m;
  }
  auto cur = getT(x, v);
  long double del = cur.first;
  while (cur.first < t && iter--) {
    for (int i = 0; i < n; i++) {
      x[i] += v[i] * (del);
    }
    sort(x.begin(), x.end());
    auto vv = getV(m[cur.second], v[cur.second], m[cur.second + 1],
                   v[cur.second + 1]);
    v[cur.second] = vv.first;
    v[cur.second + 1] = vv.second;
    auto y = getT(x, v);
    del = y.first;
    cur = {del + cur.first, y.second};
  }
  del -= cur.first - t;
  for (int i = 0; i < n; i++) {
    x[i] += v[i] * del;
  }
  vector<int> ip(n);
  for (int i = 0; i < n; i++) {
    ip[p[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    cout << fixed << setprecision(8) << x[ip[i]] << '\n';
  }
  return 0;
}