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 int max_n = 11, inf = 111111111;
const double eps = 1e-9;
struct shar {
  double x, v, m;
  void read() { cin >> x >> v >> m; }
};
void update_v(shar &a, shar &b) {
  double v1, v2;
  v1 = ((a.m - b.m) * a.v + 2 * b.m * b.v) / (a.m + b.m);
  v2 = ((b.m - a.m) * b.v + 2 * a.m * a.v) / (a.m + b.m);
  a.v = v1;
  b.v = v2;
}
int n, t;
shar s[max_n];
int main() {
  cin >> n >> t;
  for (int i = 0; i < n; ++i) {
    s[i].read();
  }
  double now_t = 0;
  while (1) {
    double min_t = inf;
    int num1, num2;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        int ff = 0;
        if (s[i].x > s[j].x) {
          swap(s[i], s[j]);
          ff = 1;
        }
        if (s[i].x < s[j].x) {
          int f = 0;
          if (s[i].v < 0 && s[j].v > 0 ||
              s[i].v * s[j].v > 0 && s[i].v < s[j].v) {
            f = 1;
          }
          if (f == 0) {
            double v;
            if (s[i].v > 0 && s[j].v < 0) {
              v = s[i].v - s[j].v;
            }
            if (s[i].v * s[j].v > 0) {
              v = s[i].v - s[j].v;
            }
            double tt = (s[j].x - s[i].x) / v;
            if (tt < min_t) {
              min_t = tt;
              num1 = i;
              num2 = j;
            }
          }
        }
        if (ff == 1) {
          swap(s[i], s[j]);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      if (now_t + min_t < t) {
        s[i].x += s[i].v * min_t;
      } else {
        s[i].x += s[i].v * (t - now_t);
      }
    }
    if (now_t + min_t < t) {
      now_t += min_t;
      for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
          if (fabs(s[i].x - s[j].x) <= eps) {
            update_v(s[i], s[j]);
          }
        }
      }
    } else {
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%.10f\n", s[i].x);
  }
  return 0;
}