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 EPS = 1E-10;
inline int cmp(double x, double y = 0, double tol = EPS) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int N, T;
double S[20], V[20], M[20];
int main() {
  scanf("%d %d", &N, &T);
  for (int i = 0; i < N; i++) scanf("%lf %lf %lf", S + i, V + i, M + i);
  double t = 0.;
  vector<pair<int, int> > NV;
  while (1) {
    double t2 = 1E10;
    for (int i = 0; i < N; i++)
      for (int j = i + 1; j < N; j++)
        if (cmp(V[i], V[j]) != 0) {
          double tc = (S[j] - S[i]) / (V[i] - V[j]);
          if (cmp(tc, 0) <= 0) continue;
          if (cmp(tc, t2) < 0) NV.clear();
          if (cmp(tc, t2) <= 0) NV.push_back(pair<int, int>(i, j)), t2 = tc;
        }
    if (cmp(t + t2, T) >= 0) break;
    for (int i = 0; i < N; i++) S[i] = S[i] + V[i] * t2;
    for (int i = 0; i < NV.size(); i++) {
      int u = NV[i].first, v = NV[i].second;
      double v1 = V[u], v2 = V[v], m1 = M[u], m2 = M[v];
      V[u] = ((m1 - m2) * v1 + 2 * m2 * v2) / (m1 + m2);
      V[v] = ((m2 - m1) * v2 + 2 * m1 * v1) / (m2 + m1);
    }
    t += t2;
  }
  for (int i = 0; i < N; i++) {
    S[i] = S[i] + V[i] * (T - t);
    printf("%.10lf\n", S[i]);
  }
  return 0;
}