Under construction

Still being built. Things may change

Blog Rating Game

Interview

Time limit2sMemory limit1024 MB

Summary
Given fixed daily changes and bounded unknown changes, find the first day the rating can exceed M (Petya) and the first day it can drop below -M (Vasya).
Level

Easy3 of 10

Topics
Prefix sum, Simulation
Solved
No attempts yet

Statement

Petya and Vasya are ordinary boys and the only readers of Seryozha's ordinary blog. Petya likes the blog very much, and Vasya dislikes it exactly as much. The two love to argue. NN days ago, when the blog rating was RR, they argued about how much the rating would change over these NN days.

On some days Petya pressed the "+1" button and raised the rating by 1. Likewise, Vasya sometimes pressed the "-1" button and lowered the rating by 1. If on some day Petya pressed "+1" and Vasya pressed "-1" as well, the server could not handle the load, a system failure happened, and the rating changed by an arbitrary integer whose absolute value does not exceed a given number KK.

Today Petya and Vasya decided to settle the argument. However, a third reader joined the blog, the server stopped working altogether, and the final rating is unknown. So they agreed that Petya wins if on some day the rating is greater than MM, and Vasya wins if on some day the rating is less than −M-M. Using the days on which each of them pressed the buttons, find who had a chance to win, and the earliest day on which that could have happened.

Input

The first line contains four integers NN, MM, KK, and RR (1≤N,M,K≤1051 \le N,M,K \le 10^5, ∣R∣≤1000|R| \le 1000, ∣R∣≤M|R| \le M). RR is the rating of Seryozha's blog at the start of the argument.

Each of the next NN lines contains two integers aia_i and bib_i. ai=1a_i = 1 if Vasya pressed his button on day ii, and ai=0a_i = 0 otherwise. Likewise, bi=1b_i = 1 if Petya pressed his button on day ii, and bi=0b_i = 0 otherwise.

Output

Print two numbers. The first is the smallest day number on which Petya could have won, and the second is the smallest day number on which Vasya could have won. If a player could not win, print −1-1 in place of that day number.

Examples3

  1. Example 1

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

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

    Input
    2 4 5 2
    1 1
    1 1
    
    Expected output
    1 2