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;
bool feq(double a, double b) { return abs(a - b) < 1e-7; }
struct ball {
  double pos;
  double speed;
  double weight;
  double time;
  int name;
  bool operator<(const ball& comp) const { return pos < comp.pos; }
  bool operator>(const ball& comp) const { return pos > comp.pos; }
};
struct bounce {
  int b1, b2;
  double time;
  bool operator<(const bounce& comp) const { return time > comp.time; }
  bool operator>(const bounce& comp) const { return time < comp.time; }
};
int main() {
  int n, T;
  cin >> n >> T;
  vector<ball> balls(n);
  for (int i = 0; i < n; i++) {
    cin >> balls[i].pos >> balls[i].speed >> balls[i].weight;
    balls[i].time = 0;
    balls[i].name = i;
  }
  sort(balls.begin(), balls.end());
  priority_queue<bounce> pq;
  for (int i = 0; i < n - 1; i++) {
    bounce b;
    b.b1 = i;
    b.b2 = i + 1;
    double t;
    if (balls[i].speed == balls[i + 1].speed) continue;
    t = (balls[i].pos - balls[i + 1].pos) /
        (balls[i + 1].speed - balls[i].speed);
    if (t < 0) continue;
    b.time = t;
    pq.push(b);
  }
  vector<int> lastchoques;
  double lastt = 0;
  while (pq.empty() == false) {
    bounce current = pq.top();
    pq.pop();
    if (current.time >= T) break;
    if (current.time < lastt - 1e-7) continue;
    int i = current.b1;
    double realt;
    if (feq(balls[i].speed, balls[i + 1].speed)) continue;
    realt = (balls[i].pos - balls[i + 1].pos - balls[i].time * balls[i].speed +
             balls[i + 1].time * balls[i + 1].speed) /
            (balls[i + 1].speed - balls[i].speed);
    if (!feq(realt, current.time)) continue;
    if (feq(lastt, realt)) {
      bool cont = false;
      for (int j = 0; j < lastchoques.size(); j++) {
        if (lastchoques[j] == i) cont = true;
      }
      if (cont) continue;
    } else {
      lastchoques.clear();
    }
    lastt = realt;
    lastchoques.push_back(i);
    double newv1 = ((balls[i].weight - balls[i + 1].weight) * balls[i].speed +
                    2 * balls[i + 1].weight * balls[i + 1].speed) /
                   (balls[i + 1].weight + balls[i].weight);
    double newv2 =
        ((balls[i + 1].weight - balls[i].weight) * balls[i + 1].speed +
         2 * balls[i].weight * balls[i].speed) /
        (balls[i + 1].weight + balls[i].weight);
    double newx = balls[i].pos + balls[i].speed * (realt - balls[i].time);
    balls[i].pos = newx;
    balls[i].speed = newv1;
    balls[i].time = realt;
    balls[i + 1].pos = newx;
    balls[i + 1].speed = newv2;
    balls[i + 1].time = realt;
    if (i > 0) {
      if (!feq(balls[i].speed, balls[i - 1].speed)) {
        double t;
        t = (balls[i - 1].pos - balls[i].pos -
             balls[i - 1].time * balls[i - 1].speed +
             balls[i].time * balls[i].speed) /
            (balls[i].speed - balls[i - 1].speed);
        if (t > realt) {
          bounce b;
          b.b1 = i - 1;
          b.b2 = i;
          b.time = t;
          pq.push(b);
        }
      }
    }
    if (i + 2 < n) {
      if (!feq(balls[i + 1].speed, balls[i + 2].speed)) {
        double t;
        t = (balls[i + 1].pos - balls[i + 2].pos -
             balls[i + 1].time * balls[i + 1].speed +
             balls[i + 2].time * balls[i + 2].speed) /
            (balls[i + 2].speed - balls[i + 1].speed);
        if (t > realt) {
          bounce b;
          b.b1 = i + 1;
          b.b2 = i + 2;
          b.time = t;
          pq.push(b);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (balls[j].name == i) {
        double lastpos;
        lastpos = balls[j].pos + (T - balls[j].time) * balls[j].speed;
        printf("%0.9f\n", lastpos);
      }
    }
  }
}