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>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
char _inBuf[32768];
int _ip = 0, _il = 0;
bool _ioError = false;
inline char nc() {
  if (_ip == _il) {
    _il = fread(_inBuf, 1, 32768, stdin);
    _ip = 0;
    if (_il == 0) {
      _ioError = true;
      return -1;
    }
  }
  return _inBuf[_ip++];
}
inline int ni() {
  char ch = nc();
  for (; ch == ' ' || ch == '\t' || ch == '\n'; ch = nc())
    ;
  if (_ioError) return -1;
  int sign = 1;
  if (ch == '-') {
    sign = -1;
    ch = nc();
  }
  int res = 0;
  for (; ch >= '0' && ch <= '9'; ch = nc()) {
    res = ((res << 3) + (res << 1));
    res += ch - '0';
  }
  return sign * res;
}
inline long long nl() {
  char ch = nc();
  for (; ch == ' ' || ch == '\t' || ch == '\n'; ch = nc())
    ;
  if (_ioError) return -1;
  long long sign = 1;
  if (ch == '-') {
    sign = -1;
    ch = nc();
  }
  long long res = 0;
  for (; ch >= '0' && ch <= '9'; ch = nc()) {
    res = ((res << 3) + (res << 1));
    res += ch - '0';
  }
  return sign * res;
}
inline int ns(char* s) {
  char* os = s;
  char ch = nc();
  for (; ch == ' ' || ch == '\t' || ch == '\n'; ch = nc())
    ;
  if (_ioError) return 0;
  for (; ch != ' ' && ch != '\t' && ch != '\n' && !_ioError; ch = nc()) {
    *s++ = ch;
  }
  *s = '\0';
  return s - os;
}
char _outBuf[32768];
int _op = 0;
inline void out(char ch) {
  if (_op == 32768) {
    fwrite(_outBuf, 1, 32768, stdout);
    _op = 0;
  }
  _outBuf[_op++] = ch;
}
inline void out(int v) {
  static char s[10];
  if (v == 0) {
    out('0');
    return;
  }
  if (v < 0) {
    out('-');
    v = -v;
  }
  int sp = 0;
  while (v > 0) {
    s[sp++] = v % 10 + '0';
    v /= 10;
  }
  while (--sp >= 0) out(s[sp]);
}
inline void out(long long v) {
  static char s[20];
  if (v == 0) {
    out('0');
    return;
  }
  if (v < 0) {
    out('-');
    v = -v;
  }
  int sp = 0;
  while (v > 0) {
    s[sp++] = v % 10 + '0';
    v /= 10;
  }
  while (--sp >= 0) out(s[sp]);
}
inline void out(const char* s) {
  for (; *s != '\0'; s++) out(*s);
}
inline void _flush() {
  if (_op > 0) {
    fwrite(_outBuf, 1, _op, stdout);
    _op = 0;
  }
}
void solve();
int main() {
  solve();
  _flush();
  return 0;
}
struct Ball {
  double x, v, m;
  int index;
  bool operator<(const Ball& r) const { return x < r.x; }
};
Ball a[10];
double o[10];
void solve() {
  int n = ni();
  double T = ni();
  for (int i = 0; i < n; i++) {
    a[i].x = ni();
    a[i].v = ni();
    a[i].m = ni();
    a[i].index = i;
  }
  sort(a, a + n);
  double t = 0;
  while (t < T) {
    double dt = T - t;
    for (int i = 0; i < n - 1; i++) {
      if (a[i + 1].v - a[i].v < 0) {
        dt = min(dt, (a[i + 1].x - a[i].x) / (a[i].v - a[i + 1].v));
      }
    }
    for (int i = 0; i < n; i++) {
      a[i].x += a[i].v * dt;
    }
    for (int i = 0; i < n - 1; i++) {
      if (fabs(a[i + 1].x - a[i].x) < 1.0E-7) {
        double v1 = a[i].v, v2 = a[i + 1].v;
        double m1 = a[i].m, m2 = a[i + 1].m;
        a[i].v = ((m1 - m2) * v1 + 2.0 * m2 * v2) / (m1 + m2);
        a[i + 1].v = ((m2 - m1) * v2 + 2.0 * m1 * v1) / (m1 + m2);
      }
    }
    t += dt;
  }
  for (int i = 0; i < n; i++) {
    o[a[i].index] = a[i].x;
  }
  char s[50];
  for (int i = 0; i < n; i++) {
    sprintf(s, "%.10lf", o[i]);
    out(s);
    out('\n');
  }
}