#P8685. Priority Cache Simulation

    ID: 21851 Type: Default 1000ms 256MiB

Priority Cache Simulation

Priority Cache Simulation

There are N restaurants in the "Baoleme" food delivery system, numbered from 1 to N. Initially (at time 0) each restaurant has a priority of 0.

Time proceeds in discrete units. At each time unit:

  • If a restaurant receives no orders, its priority decreases by 1 (but not below 0).
  • If a restaurant receives orders, its priority increases by 2 for each order (i.e. if it receives k orders then its priority increases by 2×k), and it does not decrease.

The system maintains a priority cache. At the end of each time unit, the following update is performed:

  • If a restaurant's priority is greater than 5, it is added to the priority cache.
  • If a restaurant's priority is less than or equal to 3, it is removed from the cache.
  • If the priority is 4 or 5, its cache status remains unchanged.

You are given M orders that occur within T time units. Each order is described by the time it is received and the restaurant number. Simulate the system and determine how many restaurants are in the priority cache at time T.

Note: If a restaurant is not in the cache, it only gets added when its priority becomes greater than 5. Once in the cache, it remains until its priority falls to 3 or lower.

inputFormat

The first line contains three integers N, M and T, representing the number of restaurants, the number of orders, and the total number of time units, respectively.

Then, M lines follow. Each of these lines contains two integers t and r (1 ≤ t ≤ T, 1 ≤ r ≤ N) indicating that an order for restaurant r is received at time t.

outputFormat

Output a single integer: the number of restaurants that are in the priority cache at time T.

sample

3 4 3
1 1
2 1
2 2
3 3
0