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>
bool MinPlace(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool MaxPlace(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    out << v[i];
    if (i != (int)v.size() - 1) out << ", ";
  }
  out << "]";
  return out;
}
struct ball {
  double x, v;
  int m, id;
  bool operator<(const ball &b) const { return x < b.x; }
  ball(double x, double v, int m, int id) : x(x), v(v), m(m), id(id){};
};
struct col {
  double t;
  int i, j;
  bool operator<(const col &b) const { return t > b.t; }
  bool operator==(const col &b) const {
    return t == b.t and i == b.i and j == b.j;
  }
  bool operator!=(const col &b) const { return !(this->operator==(b)); }
  col(double t, int i, int j) : t(t), i(i), j(j){};
};
vector<ball> balls;
priority_queue<col> cols;
col getCol(ball a, ball b) {
  if (a.x > b.x) return getCol(b, a);
  col ret(101.0, min(a.id, b.id), max(a.id, b.id));
  if (a.v - b.v > 0) ret.t = (b.x - a.x) / (a.v - b.v);
  return ret;
}
void collide(col c, int t) {
  if ((getCol(balls[c.i], balls[c.j]) != c) || (c.t > t)) return;
  ball &one = balls[c.i];
  ball &two = balls[c.j];
  double pos = one.x + c.t * one.v;
  double v1p = ((one.m - two.m) * one.v + 2 * two.m * two.v) / (one.m + two.m);
  double v2p = ((two.m - one.m) * two.v + 2 * one.m * one.v) / (one.m + two.m);
  one.v = v1p;
  two.v = v2p;
  one.x = pos - v1p * c.t;
  two.x = pos - v2p * c.t;
  col c1(0, 0, 0);
  for (int i = 0; i < balls.size(); i++) {
    if (i == c.i || i == c.j) continue;
    c1 = getCol(one, balls[i]);
    if (c1.t > c.t) cols.push(c1);
    c1 = getCol(two, balls[i]);
    if (c1.t > c.t) cols.push(c1);
  }
}
ostream &operator<<(ostream &out, const ball &b) {
  out << "[";
  out << "x : " << b.x << ", ";
  out << "v : " << b.v << ", ";
  out << "m : " << b.m << ", ";
  out << "id : " << b.id << " ]\n";
  return out;
}
ostream &operator<<(ostream &out, const col &c) {
  out << "[";
  out << "t : " << c.t << ", ";
  out << "i : " << c.i << ", ";
  out << "j : " << c.j << " ]\n";
  return out;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, t;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    double x, v;
    int m;
    cin >> x >> v >> m;
    balls.emplace_back(x, v, m, i);
    for (int j = 0; j < i; j++) cols.push(getCol(balls[i], balls[j]));
  }
  while (!cols.empty()) {
    col c1 = cols.top();
    collide(c1, t);
    cols.pop();
  }
  cout << setprecision(4) << fixed;
  for (int i = 0; i < n; i++) cout << (balls[i].x + balls[i].v * t) << "\n";
}