Sweet War

No attempts yetTime limit1sMemory limit256 MB

Problem

There are two countries, Imperial Cacao and the Principality of Cocoa. Alice, the Empress of Cacao, and Brianna, the Princess of Cocoa, are friends, and both of them love chocolate.

One day Alice found a transparent tube filled with chocolate balls. The tube has a single opening at its top end, and it is so narrow that the chocolate balls sit in one line. The balls are numbered 11 through NN. Ball 11 is next to the opening, ball 22 is right below it, and ball NN is at the bottom of the tube. A ball can leave the tube only through the opening, so the balls must be taken out in increasing order of their numbers.

Alice visited Brianna to share the tube. They looked at the balls carefully and decided that ball ii has nutrition value rir_i and deliciousness sis_i. Each of them wants to maximize the total deliciousness of the balls she eats. To settle this peacefully, they play a game with the following rules.

  1. Alice starts with energy AA and Brianna starts with energy BB. Both are nonnegative integers.
  2. The two players take turns, and on her turn a player takes one of the two actions below.
    • Pass: she eats nothing. She gets a little hungry, so her energy level drops by 11. She cannot pass when her energy level is 00.
    • Eat: she eats the topmost chocolate ball. If that ball is ball ii, she gains deliciousness sis_i and her energy level rises by rir_i. Her energy level does not drop by 11 in this case. Ball ii is removed from the tube.
  3. Alice takes the first turn.
  4. The game ends when every chocolate ball has been eaten.

Compute the total deliciousness Alice gets and the total deliciousness Brianna gets when both play optimally.

Input

The input is a single test case in the following format.

N A B
r1 s1
r2 s2
...
rN sN

The first line has three integers NN, AA, and BB. NN is the number of chocolate balls, and AA and BB are the initial energy levels of Alice and Brianna. Each of the next NN lines describes one ball, from the top of the tube down. The ii-th of those lines has the nutrition value rir_i and the deliciousness sis_i of ball ii.

  • 1N1501 \le N \le 150
  • 0A,B,ri1090 \le A, B, r_i \le 10^9
  • 0si0 \le s_i
  • i=1Nsi150\sum_{i=1}^{N} s_i \le 150

Output

Print two integers on one line, separated by a space: the total deliciousness Alice gets and the total deliciousness Brianna gets when both play optimally.