Skip to main content

Zomato

Zomato OA 2022 - Traffic Vicinity Calculation


Somewhere, at some point in time, there is/will be a vehicular traveling system where 1 Kilometer is the basic unit of traversal. A vehicle can either stay at rest or travel a distance which is a multiple of 1 Km, i.e., distances like 2, 3, 4, 10, and 35 Km are valid, but distances like 2.5, 6.34, and 0.25 Km are invalid.

During the age of this system, there is a traffic policeman who stands at the intersection of 4 roads. Due to development in the city, a few barriers are placed on some of the roads at certain distances from the intersection point.

Measurements are based on Cartesian coordinates, where each unit represents a kilometer. You enter into the system and are provided with the coordinates of the intersection point, the maximum north distance a vehicle can cover, the maximum eastern distance a vehicle can cover, and the coordinates of the barriers.

You have to determine the sum of the total kilometers in which the policeman has vicinity.

Example:

  • The coordinate of the intersection point: (4, 3)
  • The maximum north distance: 8 Km
  • The maximum east distance: 8 Km
  • Coordinates of barriers: (1, 3), (4, 6), (5, 3)

Input Format

  • First line: Two integers denoting maximum north and east distance.
  • Second line: Two integers denoting the coordinates of the intersection.
  • Third line: An integer 'k' denoting the number of barriers.
  • Next line: Coordinates of barriers.

Output Format

  • An integer denoting the sum of the kilometers in which the police officer has his vicinity.

Constraints

  • 1 <= north distance, east distance <= 10000
  • (0, 0) <= coordinates of intersection <= (10000, 10000)
  • 1 <= number of barriers <= 1000
  • (0, 0) <= coordinates of barriers <= (10000, 10000)

Example


Sample Input:

8 8  
4 3  
3  
1 3 4 6 5 3  

Sample Output: