Garden

Time limit1sMemory limit128 MB

Summary
Place two non-overlapping rectangles, each holding exactly k roses, and minimize the sum of their perimeters over an l by w grid with n roses.
Level

Hard8 of 10

Topics
Array, Prefix sum, Brute force, Implementation
Solved
No attempts yet

Problem

Jaehyeon owns the most beautiful garden, and has planted nn roses in it. On a summer day when every flower is in full bloom, Jaehyeon looks at the beautiful roses and suddenly begins to worry about the national economy, so he hires two gardeners, Park Seungwon and Shin Seungwon, to lower unemployment and stimulate the economy.

The garden is a rectangle ll meters wide and ww meters tall, divided into l×wl \times w unit square cells of side 11 meter. The garden's sides are parallel to the xx- and yy-axes, and every cell inside the garden can be described by integer coordinates (x,y)(x, y) with 1≤x≤l1 \le x \le l and 1≤y≤w1 \le y \le w.

A rectangular region with the four corners (l1,w1)(l_1, w_1), (l1,w2)(l_1, w_2), (l2,w1)(l_2, w_1), (l2,w2)(l_2, w_2) contains every cell (x,y)(x, y) with 1≤l1≤l2≤l1 \le l_1 \le l_2 \le l and 1≤w1≤w2≤w1 \le w_1 \le w_2 \le w (that is, l1≤x≤l2l_1 \le x \le l_2 and w1≤y≤w2w_1 \le y \le w_2), and its perimeter is 2⋅(l2−l1+1)+2⋅(w2−w1+1)2 \cdot (l_2 - l_1 + 1) + 2 \cdot (w_2 - w_1 + 1).

Jaehyeon wants to build two non-overlapping rectangular fences in the garden so that each fenced region contains exactly the same number of roses, kk. He plans to assign the two regions to Park Seungwon and Shin Seungwon.

Unfortunately, the fences are imported, so they do not help the economy at all. Therefore Jaehyeon wants to minimize the total fence length (the sum of the two perimeters) to boost domestic demand.

The two regions must not share any cell, and each region must contain exactly kk roses. Where the two fences touch, the fence is built twice, so that shared length is counted twice in the total.

Given the size of the garden, the positions of the roses, and the number of roses each region must contain, write a program that finds two regions satisfying the conditions with the minimum total fence length. A single cell may contain several roses.

Input

The first line contains the garden's width and height ll and ww. (1≤l,w≤2501 \le l, w \le 250)

The second line contains the total number of roses nn and the number of roses each region must contain kk. (2≤n≤50002 \le n \le 5000, 1≤k≤n/21 \le k \le n/2)

Each of the next nn lines contains two integers lil_i and wiw_i, the cell of the ii-th rose. (1≤li≤l1 \le l_i \le l, 1≤wi≤w1 \le w_i \le w) A single cell may contain multiple roses.

Output

Print, on one line, the minimum possible sum of the two regions' perimeters. If no two regions can satisfy the conditions, print NO.

Hint

Examples1

  1. Example 1

    Input
    6 5
    7 3
    3 4
    3 3
    6 1
    1 1
    5 5
    5 5
    3 1
    
    Expected output
    22