Under construction

Still being built. Things may change

Shopping Plans

Time limit2sMemory limit512 MB

Summary
Given items with types and costs and a count range per type, find the K cheapest subsets whose per-type counts fall within their ranges.
Level

Hard9 of 10

Topics
Divide and conquer, Heap, Sorting, Prefix sum
Solved
No attempts yet

Problem

You are shopping from a store that sells a total of NN items. The ii-th item has a type aia_i, which is an integer between 11 and MM. A feasible shopping plan is a subset of these items such that for every type jj, the number of items of type jj is in the interval [xj,yj][x_j, y_j].

The ii-th item in the store has a cost of cic_i, and the cost of a shopping plan is the sum of the costs of the items in the plan. Find the costs of the KK cheapest feasible shopping plans. If two different shopping plans have the same cost, they are counted separately in the output.

Input

The first line contains three space-separated integers NN, MM, and KK (1≤N,M,K≤2000001 \le N, M, K \le 200000). The next NN lines each contain two space-separated integers aia_i and cic_i (1≤ai≤M1 \le a_i \le M, 1≤ci≤1091 \le c_i \le 10^9). The next MM lines each contain two space-separated integers xjx_j and yjy_j (0≤xj≤yj≤N0 \le x_j \le y_j \le N).

Output

Output KK lines. On the ii-th line, output the cost of the ii-th cheapest feasible shopping plan, or −1-1 if there are fewer than ii feasible shopping plans.

Hint

A feasible shopping plan must combine exactly one item with a cost in {5,3,6}\{5, 3, 6\} with exactly one item with a cost in {3,1}\{3, 1\}.

Examples1

  1. Example 1

    Input
    5 2 7
    1 5
    1 3
    2 3
    1 6
    2 1
    1 1
    1 1
    
    Expected output
    4
    6
    6
    7
    8
    9
    -1