Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment.

The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other robots. More precisely, for the i-th robot we know value ci — the number of robots it can carry. In this case, each of ci transported robots can additionally carry other robots.

However, the robots need to be filled with fuel to go, so Valera spent all his last money and bought S liters of fuel. He learned that each robot has a restriction on travel distances. Thus, in addition to features ci, the i-th robot has two features fi and li — the amount of fuel (in liters) needed to move the i-th robot, and the maximum distance that the robot can go.

Due to the limited amount of time and fuel, Valera wants to move the maximum number of robots to the luggage compartment. He operates as follows. 

  * First Valera selects some robots that will travel to the luggage compartment on their own. In this case the total amount of fuel required to move all these robots must not exceed S. 
  * Then Valera seats the robots into the compartments, so as to transport as many robots as possible. Note that if a robot doesn't move by itself, you can put it in another not moving robot that is moved directly or indirectly by a moving robot. 
  * After that all selected and seated robots along with Valera go to the luggage compartment and the rest robots will be lost. 



There are d meters to the luggage compartment. Therefore, the robots that will carry the rest, must have feature li of not less than d. During the moving Valera cannot stop or change the location of the robots in any way.

Help Valera calculate the maximum number of robots that he will be able to take home, and the minimum amount of fuel he will have to spend, because the remaining fuel will come in handy in Valera's research.

Input

The first line contains three space-separated integers n, d, S (1 ≤ n ≤ 105, 1 ≤ d, S ≤ 109). The first number represents the number of robots, the second one — the distance to the luggage compartment and the third one — the amount of available fuel.

Next n lines specify the robots. The i-th line contains three space-separated integers ci, fi, li (0 ≤ ci, fi, li ≤ 109) — the i-th robot's features. The first number is the number of robots the i-th robot can carry, the second number is the amount of fuel needed for the i-th robot to move and the third one shows the maximum distance the i-th robot can go.

Output

Print two space-separated integers — the maximum number of robots Valera can transport to the luggage compartment and the minimum amount of fuel he will need for that. If Valera won't manage to get any robots to the luggage compartment, print two zeroes.

Examples

Input

3 10 10
0 12 10
1 6 10
0 1 1


Output

2 6


Input

2 7 10
3 12 10
5 16 8


Output

0 0


Input

4 8 10
0 12 3
1 1 0
0 3 11
1 6 9


Output

4 9
#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long c, f, l;
  bool operator<(const Node& nd) const { return f < nd.f; }
};
Node Empty[100010];
Node NonE[100010];
int ect, nct;
int n;
long long D, S;
void runEmpty(long long& res, long long& ans) {
  sort(Empty, Empty + ect);
  res = 0;
  ans = 0;
  for (int i = 0; i < ect; ++i) {
    if (Empty[i].l >= D) {
      if (res + Empty[i].f <= S) {
        res += Empty[i].f;
        ans++;
      } else {
        break;
      }
    }
  }
}
int main() {
  scanf("%d%I64d%I64d", &n, &D, &S);
  ect = nct = 0;
  long long sum = 0;
  bool hasone = false;
  for (int i = 0; i < n; ++i) {
    long long c, f, l;
    scanf("%I64d%I64d%I64d", &c, &f, &l);
    if (c) {
      NonE[nct].c = c;
      NonE[nct].f = f;
      NonE[nct].l = l;
      nct++;
      sum += c;
      if (l >= D && f <= S) hasone = true;
    } else {
      Empty[ect].c = c;
      Empty[ect].f = f;
      Empty[ect].l = l;
      ect++;
    }
  }
  if (hasone) {
    sum -= nct - 1;
    long long left = ect - sum > 0 ? ect - sum : 0;
    sort(NonE, NonE + nct);
    sort(Empty, Empty + ect);
    long long res = 0;
    int pn, pe;
    pn = pe = 0;
    while (pn < nct) {
      if (NonE[pn].l < D)
        pn++;
      else
        break;
    }
    res = NonE[pn++].f;
    NonE[nct].f = 1LL << 61;
    Empty[ect].f = 1LL << 61;
    while (left) {
      while (pn < nct) {
        if (NonE[pn].l < D)
          pn++;
        else
          break;
      }
      while (pe < ect) {
        if (Empty[pe].l < D)
          pe++;
        else
          break;
      }
      if (NonE[pn].f < Empty[pe].f) {
        if (res + NonE[pn].f <= S) {
          left--;
          res += NonE[pn].f;
          pn++;
        } else {
          break;
        }
      } else {
        if (res + Empty[pe].f <= S) {
          left--;
          res += Empty[pe].f;
          pe++;
        } else {
          break;
        }
      }
    }
    long long a = n - left;
    long long b = res;
    long long c, d;
    runEmpty(d, c);
    if (a < c || (a == c && b > d)) {
      a = c;
      b = d;
    }
    printf("%I64d %I64d\n", a, b);
  } else {
    long long res, ans;
    runEmpty(res, ans);
    printf("%I64d %I64d\n", ans, res);
  }
  return 0;
}
