This page is still under construction.

Parts of this page are still being built. What you see may change.

Maxim's Triangle

Interview

Time limit2sMemory limit512 MB

Summary
Given a sequence of probe frequencies and whether each is closer to or farther from an unknown value, find the min and max possible value of that unknown.
Level

Medium6 of 10

Topics
Math, Binary search, Intervals, Geometry
Solved
No attempts yet

Problem

Since childhood, Maxim was a decent musician and a jack of all trades. Recently he made a simple percussion instrument by himself: a triangle. He needs to find out the frequency of the sound produced by his instrument.

Maxim has a professional musical tuner, which can play a note with a given frequency. Maxim acts as follows: he turns on notes with different frequencies on the tuner, and for each note he determines by ear whether it is closer to or farther from the sound produced by the triangle than the previous note. Since Maxim has perfect pitch, he always determines this absolutely correctly.

Maxim showed you a record containing the sequence of frequencies he set on the tuner, and for each note starting from the second one it records whether it is closer to or farther from the triangle's sound than the previous note. It is known in advance that the frequency of Maxim's triangle is at least 30 hertz and at most 4000 hertz.

Write a program that determines the interval in which the frequency of the triangle's sound can lie.

Input

The first line of the input contains the integer nn, the number of notes Maxim played with the tuner (2≤n≤10002 \le n \le 1000). The next nn lines contain Maxim's record, and each line contains two components: a real number fif_i, the frequency set on the tuner in hertz (30≤fi≤400030 \le f_i \le 4000), and the word closer or the word further for every frequency except the first one.

The word closer means that the frequency of this note is closer to the frequency of the triangle's sound than the frequency of the previous note, which is formally described by the relation: ∣fi−fтреуг.∣<∣fi−1−fтреуг.∣|f_i - f_{\text{треуг.}}| < |f_{i-1} - f_{\text{треуг.}}|.

The word further means that the frequency of this note is farther than the previous one.

If the next note turned out to be as close to the triangle's sound as the previous note, Maxim could write either of the two words above.

It is guaranteed that the results Maxim obtained are consistent.

Output

Output two real numbers separated by a space: the smallest and the largest possible value of the frequency of the sound of the triangle Maxim made.

Examples2

  1. Example 1

    Input
    3
    440.0
    220.0 closer
    300.0 further
    
    Expected output
    30.0 260.0
    
  2. Example 2

    Input
    4
    554.0
    880.0 further
    440.0 closer
    622.0 closer
    
    Expected output
    531.0 660.0