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 Tp>
inline void outarr(Tp _array, const std::size_t _N, const char* _delim = " ") {
  Tp end = std::next(_array, _N);
  for (Tp current = _array; current != end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
struct TBall {
  int M;
  double X;
  double V;
};
TBall arr[10];
int id[10];
double NewV(const TBall& a, const TBall& b) {
  return ((a.M - b.M) * a.V + 2.0 * b.M * b.V) / (a.M + b.M);
}
double TimeCollide(int i, int j) {
  if (abs(arr[i].X - arr[j].X) < 1e-6) {
    return 200;
  }
  if (arr[i].X > arr[j].X) {
    swap(i, j);
  }
  if (arr[i].V > 0 && arr[j].V < 0) {
    return (arr[j].X - arr[i].X) / (abs(arr[j].V) + abs(arr[i].V));
  }
  if (arr[i].V > 0 && arr[j].V > 0 && arr[i].V > arr[j].V ||
      arr[i].V < 0 && arr[j].V < 0 && arr[j].V < arr[i].V) {
    return (arr[j].X - arr[i].X) / abs(abs(arr[j].V) - abs(arr[i].V));
  }
  return 200;
}
vector<pii> pos;
char used[10];
double Step(int n, double t) {
  double mint = t;
  pos.clear();
  memset(used, 0, sizeof(used));
  sort(id, id + n, [](int i, int j) { return arr[i].X < arr[j].X; });
  for (int q = 1; q < n; ++q) {
    int i = id[q - 1];
    int j = id[q];
    double nt = TimeCollide(i, j);
    if (abs(nt - mint) < 1e-6) {
      pos.emplace_back(i, j);
    } else if (nt < mint) {
      mint = nt;
      pos.clear();
      pos.emplace_back(i, j);
    }
  }
  for (auto&& [i, j] : pos) {
    arr[i].X += arr[i].V * mint;
    arr[j].X += arr[j].V * mint;
    double vi = NewV(arr[i], arr[j]);
    double vj = NewV(arr[j], arr[i]);
    arr[i].V = vi;
    arr[j].V = vj;
    used[i] = used[j] = true;
  }
  for (int i = 0; i < (n); ++i) {
    if (!used[i]) {
      arr[i].X += arr[i].V * mint;
    }
  }
  return t - mint;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  double t;
  cin >> n >> t;
  for (int i = 0; i < (n); ++i) {
    cin >> arr[i].X >> arr[i].V >> arr[i].M;
    id[i] = i;
  }
  while (t > 0) {
    t = Step(n, t);
  }
  cout.setf(ios::fixed);
  cout.precision(7);
  for (int i = 0; i < (n); ++i) {
    cout << arr[i].X << "\n";
  }
  return 0;
}