Under construction

Still being built. Things may change

Yunny's Trip

Time limit2sMemory limit512 MB

Summary
Find the minimum stamina needed to walk from (0, 0) to (Ex, Ey) with unit moves (cost 1) and repeatable item vectors (cost 2), never dropping below 0.
Level

Hard8 of 10

Topics
Math, Number theory, Greedy
Solved
No attempts yet

Problem

Yunny enters Uniworld, her virtual world, to take a short break. Uniworld is an infinite two-dimensional grid, and Yunny is currently standing at (0,0)(0, 0). To reach her destination (Ex,Ey)(E_x, E_y), Yunny can repeat the following two kinds of actions.

  1. Move one cell to an adjacent cell. That is, change the xx coordinate by 11 or change the yy coordinate by 11. This action consumes 11 stamina.
  2. Use one of the items she is carrying. Each item is given as (ai,bi)(a_i, b_i). Using it increases her xx coordinate by aia_i and her yy coordinate by bib_i. So if she is at (x,y)(x, y), using the item moves her to (x+ai,y+bi)(x+a_i, y+b_i). This action does not consume the item, so the same item can be used many times. It consumes 22 stamina.

If her stamina drops below 00, she returns to the real world, so she keeps her stamina at 00 or above. Yunny is frail, so her initial stamina does not exceed 55. Determine whether she can reach the destination. If she can, find the minimum stamina she must spend to get there.

Input

The first line contains the number of items NN and Yunny's initial stamina KK, separated by a space. (1≤N≤2×1051 \le N \le 2 \times 10^5; 1≤K≤51 \le K \le 5)

Each of the next NN lines contains aia_i and bib_i for one item, separated by a space. (−1012≤ai,bi≤1012-10^{12} \le a_i, b_i \le 10^{12})

The last line contains the destination ExE_x and EyE_y, separated by a space. (−1012≤Ex,Ey≤1012-10^{12} \le E_x, E_y \le 10^{12})

No item or destination is (0,0)(0, 0), and no item is given more than once.

Output

Print the minimum stamina that must be spent to reach the destination. If Yunny cannot reach the destination with her initial stamina KK, print -1.

Examples3

  1. Example 1

    Input
    3 5
    0 -2
    2 3
    2 -1
    5 2
    
    Expected output
    5
    
  2. Example 2

    Input
    3 5
    4 -1
    2 2
    0 4
    4 4
    
    Expected output
    4
    
  3. Example 3

    Input
    2 3
    3 0
    -12 -12
    4 1
    
    Expected output
    -1