#CCBCHHAI0000033. Chế độ tính điểm đến khi đạt (Score Mode Until Stop)

Chế độ tính điểm đến khi đạt (Score Mode Until Stop)

Score Mode Until Stop

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

A score calculator starts with total = 0 and count = 0. Each command pair (m, x) means: m=1 add x, m=2 subtract x, m=9 stop. Count only the add/subtract commands; do not count the terminating command. Termination is based on code 9, not on a score threshold. The final pair is 9 0.

Input

Integer pairs m x ending with 9 0. Every code belongs to {1,2,9} and 9 occurs only in the final pair. Operands of codes 1 and 2 are signed integers.

Output

Print total count on one line, separated by one space.

Subtasks

  • Subtask 1 (20%): At most 5 pairs including the terminator; ∣x∣≤10|x|\le10.
  • Subtask 2 (30%): At most 100 pairs including the terminator; ∣x∣≤1000|x|\le1000.
  • Subtask 3 (50%): At most 10000 pairs including the terminator; ∣x∣≤106|x|\le10^6.

Examples

Example 1

Input

1 10
2 3
1 -2
9 0

Output

5 3

Explanation

The totals are 10, 7 and 5. Three arithmetic commands are processed; code 9 is not counted.

Example 2

Input

9 0

Output

0 0

Explanation

The first pair terminates processing; both counters stay at zero.