This page is still under construction.

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

Gathering

Time limit3sMemory limit256 MB

Summary
Pick an integer intersection within Manhattan distance d of every house so the sum of Manhattan travel distances is smallest, or report impossible.
Level

Medium7 of 10

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

Problem

The citizens of Fictitia have had enough. The city keeps growing, and it keeps getting more boring. Fictitia has horizontal and vertical streets only, and the gap between two neighbouring parallel streets is always the same. Take that gap as distance 11.

To make their unhappiness known to the city council, a group of citizens agreed to gather at one intersection and protest. The question is which intersection. The intersections are much alike, so someone proposed picking the intersection (x∗,y∗)(x^*, y^*) that minimises the total distance everyone has to travel. Every citizen lives next to an intersection, so a citizen living at (x,y)(x, y) travels ∣x−x∗∣+∣y−y∗∣|x - x^*| + |y - y^*|.

This could be a problem for the citizens who live far away, because they might not get there in time. The group therefore decided that the chosen intersection has to be at most a distance dd away from every citizen. Under that restriction, find an intersection that minimises the total distance everyone has to travel.

Input

  • The first line has one integer nn (2≤n≤1000002 \le n \le 100000), the number of citizens.
  • Each of the next nn lines has two integers xx and yy (0≤x,y≤1090 \le x, y \le 10^9), the coordinates of one citizen's house.
  • The last line has one integer dd (0≤d≤2×1090 \le d \le 2 \times 10^9), the maximum distance each citizen should have to travel.

Several citizens can live at the same intersection.

Output

Print one line with a single integer, the smallest possible total distance that all citizens have to travel. If no intersection lies within distance dd of every citizen, print impossible instead.

Examples3

  1. Example 1

    Input
    5
    3 1
    4 1
    5 9
    2 6
    5 3
    10
    
    Expected output
    18
    
  2. Example 2

    Input
    5
    3 1
    4 1
    5 9
    2 6
    5 3
    5
    
    Expected output
    20
    
  3. Example 3

    Input
    5
    3 1
    4 1
    5 9
    2 6
    5 3
    4
    
    Expected output
    impossible