This page is still under construction.

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

KRAVE

Time limit5sMemory limit256 MB

Summary
You extend a horizontal or vertical fence from each given point across its current field and report the two resulting areas in order.
Level

Medium6 of 10

Topics
Intervals, Binary search, Simulation
Solved
No attempts yet

Problem

A meadow is an A×BA \times B rectangle. From point (X,Y)(X,Y), build a horizontal or vertical fence until it hits another fence. After each fence, print the areas of the two new fields, smaller first.

Input

AA, BB, NN, then NN lines with XX, YY, DD (11 horizontal, 22 vertical).

Output

NN lines, two 64-bit integers per line.

Examples3

  1. Example 1

    Input
    9 7
    5
    3 3 2
    7 2 1
    6 3 2
    5 4 1
    1 4 1
    
    Expected output
    21 42
    12 30
    15 15
    6 9
    9 12
    
  2. Example 2

    Input
    4 4
    3
    2 2 2
    1 2 1
    3 2 1
    
    Expected output
    8 8
    4 4
    4 4
    
  3. Example 3

    Input
    9 7
    10
    6 1 2
    2 6 2
    8 5 2
    5 2 2
    4 3 1
    1 2 1
    7 6 1
    3 4 1
    1 4 1
    7 2 1
    
    Expected output
    21 42
    14 28
    7 14
    7 21
    9 12
    4 10
    2 12
    3 9
    4 6
    4 8