Teleport

View as PDF

Submit solution


Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types

You're living in a world where teleportation has been discovered. You're a trader and you travel across the world and earn money by trading stuff with people every day.

On each day you start your journey from the city you live in, then you travel cities one by one using teleportation. To go to a city, you need to pay the transportation fee.

The transportation fee is calculated as the distance between cities on the equi­rectangular projec­tion of the world (in km). Given two cities \( A (\theta_1, \alpha_1) \) and \( B (\theta_2, \alpha_2) \) the distance is calculated as:

\( d = R * \sqrt{(\theta_2 - \theta_1)^2 + ( (\alpha_2 - \alpha_1) \cdot cos (\frac{\theta_2 + \theta_1}{2}))^2} \)

where \(\theta\) is the latitude, \(\alpha\) is the longitude of a city (in radians), \( R \) is the radius of the earth, and \( d \) is the distance between cities (in km).

By visiting each city, you'll be earning some money but losing at the same time due to transportation fees. Every day you try to leave work whenever your money becomes the highest possible profit for that day.

You start in the city you live, and you need to end your day in the same city.

  • You'll be visiting the cities in the given order.
  • If visiting a city or not does not matter, you'll prefer to visit that city.
  • For the sake of simplicity, you'll assume that the world is a perfect sphere with no axis tilt.
  • The radius of the world is 6371 km.

Input

The first line includes three integers, \(N\) the number of cities, \(\theta\), and \(\alpha\) the latitude and longitude of your city.

The following \(N\) lines include three integers, \(\theta_i\), \(\alpha_i\), and \(m_i\); the latitude and longitude of \(i^{th}\) city (in degrees), and the money you'll earn by visiting that city.

  • \( 0 < N \leq 10^4 \)
  • \( 0 < m_i \leq 10^5 \)
  • \( -90 \leq \theta \leq 90 \)
  • \( -180 \leq \alpha \leq 180 \)

Output

Print how many cities you need to visit to earn the maximum amount of money. It's also possible that you won't visit any city.

Example

Input 1:

1 20 20
40 40 6000

Output 1:

1

Explanation

Input 1: While visiting city 0, you'll spend \( 5883.88 \) (\(2941.94\) + \(2941.94\)) money, but you will earn \(6000\). As a result, you'll be earning 116.1 money.