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;
const double INF = 1e100;
const double EPS = 1e-6;
const int MAX_N = 111;
struct data_base {
  double x, v, m, time;
  data_base(double a, double b, double c) : x(a), v(b), m(c) { time = 0; }
  data_base(){};
  void get() {
    scanf("%lf%lf%lf", &x, &v, &m);
    time = 0;
  }
  void show() {
    printf("At %.4lf we have speed of %.4lf and  weight of %.4lf \n", x, v, m);
  }
};
struct s_heapbase {
  int which;
  double pos;
  double time;
};
bool operator<(s_heapbase a, s_heapbase b) { return a.time < b.time - EPS; }
bool operator>(s_heapbase a, s_heapbase b) { return a.time > b.time + EPS; }
class c_heap {
 public:
  double time_gone;
  int n;
  s_heapbase data[MAX_N];
  int where[MAX_N];
  void ini() {
    n = 0;
    time_gone = 0;
  }
  void add(int w, double t, double pos) {
    data[n].which = w;
    data[n].time = t;
    data[n].pos = pos;
    ++n;
    fix(n - 1);
    return;
  }
  void put(s_heapbase f, int t) {
    data[t] = f;
    where[f.which] = t;
    return;
  }
  void fix(int p) {
    s_heapbase tmp = data[p];
    while (p > 0 && tmp < data[p - 1 >> 1]) {
      put(data[p - 1 >> 1], p);
      p = p - 1 >> 1;
    }
    put(tmp, p);
    int next;
    while ((p << 1) + 1 < n) {
      if ((p << 1) + 1 == n - 1)
        next = (p << 1) + 1;
      else if (data[(p << 1) + 1] < data[(p << 1) + 2])
        next = (p << 1) + 1;
      else
        next = (p << 1) + 2;
      if (data[next] < tmp) {
        put(data[next], p);
        p = next;
      } else
        break;
    }
    put(tmp, p);
    return;
  }
  void change(int which, double t, double pos) {
    int p = where[which];
    data[p].time = t;
    data[p].pos = pos;
    fix(p);
    return;
  }
};
data_base ball[MAX_N];
int order[MAX_N];
inline bool operator<(data_base a, data_base b) { return a.x < b.x - EPS; }
inline bool mr(double a, double b) { return a - EPS > b; }
inline bool ls(double a, double b) { return a + EPS < b; }
inline bool zero(double a) { return a < EPS && a > -EPS; }
inline bool eq(double a, double b) { return zero(a - b); }
bool cmp(const int& a, const int& b) { return ball[a] < ball[b]; }
void all_swap(data_base& a, data_base& b, double pos) {
  double v1 = (a.m - b.m) * a.v + 2 * b.m * b.v;
  double v2 = (b.m - a.m) * b.v + 2 * a.m * a.v;
  v1 /= a.m + b.m;
  v2 /= a.m + b.m;
  a.v = v1;
  b.v = v2;
  a.x = pos;
  b.x = pos;
  return;
}
void ari(data_base a, data_base b, double& time, double& pos) {
  if (ls(a.time, b.time)) swap(a, b);
  double time_more = a.time - b.time;
  b.x += time_more * b.v;
  double cost_time = (b.x - a.x) / (a.v - b.v);
  if (ls(cost_time, 0)) {
    time = INF;
    return;
  }
  pos = a.v * cost_time + a.x;
  double pos1 = b.v * cost_time + b.x;
  time = cost_time + a.time;
  return;
}
c_heap dist;
int main() {
  int n;
  double t;
  cin >> n >> t;
  for (int i = 0; i < n; ++i) {
    ball[i].get();
    order[i] = i;
  }
  ball[n] = data_base(INF, 0, INF);
  order[n] = n;
  ball[n + 1] = data_base(-INF, 0, INF);
  order[n + 1] = n + 1;
  n += 2;
  sort(order, order + n, cmp);
  dist.ini();
  for (int i = 1; i < n; ++i) {
    double temp_time, temp_pos;
    ari(ball[order[i - 1]], ball[order[i]], temp_time, temp_pos);
    dist.add(i, temp_time, temp_pos);
  }
  while (ls(dist.data[0].time, t)) {
    int l = dist.data[0].which - 1;
    int r = dist.data[0].which;
    all_swap(ball[order[l]], ball[order[r]], dist.data[0].pos);
    ball[order[l]].time = dist.data[0].time;
    ball[order[r]].time = dist.data[0].time;
    dist.change(r, INF, 0);
    double time_to;
    double pos;
    ari(ball[order[l - 1]], ball[order[l]], time_to, pos);
    dist.change(l, time_to, pos);
    ari(ball[order[r]], ball[order[r + 1]], time_to, pos);
    dist.change(r + 1, time_to, pos);
  }
  for (int i = 0; i < n - 2; ++i)
    printf("%.4lf\n", ball[i].x + ball[i].v * (t - ball[i].time));
  return 0;
}