This page is still under construction.

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

CN Tower

Interview

Time limit1sMemory limit128 MB

Summary
Given angles of landmarks around a rotating restaurant that turns 360 degrees every 72 minutes, find the shortest time window covering all distinct angles.
Level

Medium5 of 10

Topics
Sorting, Two pointers, Math, Implementation
Solved
No attempts yet

Problem

Christy C. Coder is traveling to a programming competition. On the way she stops in Toronto to do some sightseeing. The annoying part of traveling is that everyone back home expects her to bring back pictures of everything, and Christy hates taking pictures: it makes her look like such a tourist. Fortunately, she has a plan to make her picture-taking quite painless.

At 553 m tall, the CN Tower is the world's tallest free-standing building. 351 m up the tower is the "360" rotating restaurant, which completes a full 360-degree rotation every 72 minutes. From there Christy can see the whole city and take close-up pictures of every landmark with her fancy 100x optical-zoom camera. Because the restaurant itself rotates, she only needs to stand in one place to take pictures in every direction.

The waiters insist that she order something or leave, and nothing on the menu interests her, so she must act quickly before she gets kicked out. Given the directions to the landmarks Christy wants to photograph, determine the minimum amount of time she must spend in the restaurant for it to rotate enough to bring every landmark into view. Assume Christy always points her camera exactly perpendicular to the window to minimize distortion from the glass; a landmark can therefore be photographed only at the instant the window faces its direction exactly. Several landmarks may occupy the same (angular) position, and such landmarks require only one photograph.

Because the staff only realize she is a tourist once she starts taking pictures, timing begins when she takes her first picture. Christy may therefore move to any position in the restaurant without hassle and begin taking pictures from there.

Input

The first line contains an integer nn (2≤n≤10002 \le n \le 1000), the number of landmarks Christy wants to photograph. Each of the next nn lines describes one landmark: the landmark name (a string of uppercase and lowercase letters of length at most 40), a single space, and the compass angle dd (in degrees) to that landmark from the CN Tower, where 0 = north, 90 = east, 180 = south, 270 = west. dd is a real number with 0≤d<3600 \le d < 360, given to at most two decimal places (hundredths of a degree).

Output

Print a single integer: the minimum number of seconds Christy must remain in the restaurant. If that time is not an integer number of seconds, round it up to the nearest second (take the ceiling).

Examples2

  1. Example 1

    Input
    5
    CassLoma 231
    OntarioParliament 123
    SkyDome 75
    RoyalYorkHotel 340
    PearsonAirport 165
    
    Expected output
    3012
    
  2. Example 2

    Input
    2
    North 0
    South 180
    
    Expected output
    2160