This page is still under construction.

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

Statisticians

Time limit1sMemory limit128 MB

Summary
Given a grid of counts, take the median of the mean densities over all axis-aligned subrectangles whose area lies in [a,b].
Level

Hard8 of 10

Topics
Prefix sum, Binary search, Sorting
Solved
No attempts yet

Problem

Statisticians like to compute many statistics. One simple measure is the mean: the sum of all values divided by the number of values. Another is the median: the middle value once all values have been sorted. If there is an even number of values, the median is the mean of the two middle values.

Such measures can describe, for example, the population of a country or part of it. Anne Jensen, Maria Virtanen, Jan Hansen, Erik Johansson and Jón Þórsson want to measure statistically how many statisticians there are in the Nordic countries — more precisely, how many there are per unit area. Because the population is spread out, they use a new measurement called MAD (Median of All Densities):

  1. Overlay a square grid on the map.
  2. For every axis-aligned rectangle of grid cells whose area lies within the allowed range, compute its density: the mean number of statisticians per unit area (the total inside the rectangle divided by its area).
  3. Repeat for every possible rectangle; the MAD is the median of all these densities.

Given the grid and the allowed range of rectangle areas, compute the MAD.

Input

The first line contains two space-separated integers hh and ww, the height and width of the grid (1≤h≤1401 \le h \le 140, 1≤w≤1201 \le w \le 120).

The second line contains two space-separated integers aa and bb, the lower and upper bounds on the allowed rectangle area; every considered rectangle has area in [a,b][a, b], with 1≤a≤b≤w×h1 \le a \le b \le w \times h.

Each of the next hh lines contains ww space-separated integers ss, the number of statisticians in each cell of the grid (0≤s≤100000 \le s \le 10000).

It is guaranteed that at least one rectangle has area within [a,b][a, b].

Output

Print a single line containing the MAD — the number of statisticians per unit area — rounded to three decimal places.

Examples2

  1. Example 1

    Input
    4 2
    1 8
    6 5
    2 5
    2 9
    7 13
    
    Expected output
    5.250
    
  2. Example 2

    Input
    2 3
    2 4
    6 1 4
    2 7 1
    
    Expected output
    3.667