Under construction

Still being built. Things may change

Mouse Pursuit

Interview

Time limit3sMemory limit2048 MB

Summary
Given n events, each a caught or missed mouse with a time offset and cheese and glory changes, find the totals gained in the last k seconds.
Level

Medium4 of 10

Topics
Prefix sum, Sorting, Binary search
Solved
No attempts yet

Problem

Brandon is playing the newest idle game, Mouse Pursuit. The goal of this game is to pursue mice for cheese and glory.

In Mouse Pursuit, an event consists of pursuing a mouse. If the mouse is caught, the player might earn cheese and glory. If the mouse is not caught, the player might lose cheese and glory.

Given Brandon's recent events, find how much cheese and glory Brandon earned in the last kk seconds.

Input

The first line of input contains a single integer nn (1≤n≤105)(1 \le n \le 10^5).

The next nn lines take one of two forms:

  • CAUGHT ss cc gg: A mouse was caught exactly ss seconds ago. The player gained cc pieces of cheese and gg units of glory.
  • MISS ss cc gg: A mouse was missed exactly ss seconds ago. The player lost cc pieces of cheese and gg units of glory.

For all events, 0≤c,g≤1060 \le c, g \le 10^6 and 1≤s≤1091 \le s \le 10^9. No two events happened at exactly the same time.

The last line contains a single integer kk. No event happened exactly kk seconds ago.

Output

Output two integers: the number of pieces of cheese Brandon gained in the last kk seconds, and the number of units of glory Brandon gained in the last kk seconds.

Examples1

  1. Example 1

    Input
    3
    CAUGHT 1 6 5
    MISS 4 1 2
    CAUGHT 8 0 3
    5
    
    Expected output
    5 3