Under construction

Still being built. Things may change

Boat Commuter

Interview

Time limit2sMemory limit1024 MB

Summary
Given a chronological log of pier tap events, compute each travel card's total fare, where an unfinished trip or a trip starting and ending at the same pier costs 100 pounds.
Level

Easy3 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

The Bulgarian city of Nodnol runs a boat service to ferry its residents between the trendy areas where they live and the large metallic structures where they work on the next recession.

TFN (Transport For Nodnol) has issued mm travel cards, known affectionately as "Retsyo", numbered from 11 to mm. Each pier has a card terminal where passengers tap "in" when starting a trip and tap "out" when finishing it.

Since each pier has only one card terminal, passengers use the same device to tap in and to tap out.

The cost of a trip depends on the distance travelled:

  • if the trip started at pier ii and finished at pier jj (i≠ji \ne j), its cost is ∣i−j∣|i-j| pounds;
  • if the trip started somewhere but was not finished with a tap out, it costs £100;
  • if the trip started and finished at the same pier, it also costs £100, because it is treated as an attempt to game the system.

You are given a sequence of tapping events. For each event, the pier pip_i and the card number cic_i are recorded. Determine how much the transport authority should charge each card.

Input

  • One line containing three integers: the number of piers nn, the number of travel cards mm, and the number of events kk (2≤n≤502 \le n \le 50, 1≤m,k≤1051 \le m, k \le 10^5).
  • kk further lines, each describing a tap event in chronological order.
    • The ii-th event is described by two integers pip_i and cic_i (1≤pi≤n1 \le p_i \le n, 1≤ci≤m1 \le c_i \le m).

Output

Output mm integers separated by spaces. The ii-th integer is the total charge for the ii-th card.

Examples1

  1. Example 1

    Input
    3 3 5
    1 1
    1 2
    1 2
    3 1
    2 3
    
    Expected output
    2 100 100