Rainfall

Time limit2sMemory limit128 MB

Summary
Given partial yearly rainfall records, decide for each query whether a claimed record-rain statement between two years is definitely true, possibly true, or impossible.
Level

Medium7 of 10

Topics
Binary search, Array, Greedy
Solved
No attempts yet

Problem

For each year, the officially measured amount of rain is called that year's rainfall. Based on these records, people may say, “In year X, the rainfall was the greatest since year Y.” Some yearly records may be missing, so you must decide whether each statement is certainly true, only possible, or impossible.

The statement “In year X, the rainfall was the greatest since year Y” is true when all of the following conditions hold.

  1. The rainfall is known for every year from Y through X.
  2. The rainfall in year X is less than or equal to the rainfall in year Y.
  3. For every year Z such that Y < Z < X, the rainfall in year Z is less than the rainfall in year X.

If the missing yearly rainfall values can be chosen so that the conditions hold, the answer is maybe. If the known information already makes the conditions impossible, the answer is false. If every condition is fully verified, the answer is true.

Input

The first line contains an integer n (1 <= n <= 50,000).

Each of the next n lines contains two integers y and r, meaning that the rainfall in year y is r.

  • 0 <= |y| <= 1,000,000,000
  • 1 <= r <= 1,000,000,000

The rainfall records are given in increasing order of y.

The next line contains an integer m (1 <= m <= 10,000).

Each of the next m lines contains two integers Y and X, representing the statement “In year X, the rainfall was the greatest since year Y.”

  • -1,000,000,000 <= Y < X <= 1,000,000,000

Output

For each statement, print one answer on its own line.

  • Print true if the statement is certainly true.
  • Print maybe if it could be true but cannot be confirmed.
  • Print false if it is impossible.

Examples2

  1. Example 1

    Input
    4
    2002 4920
    2003 5901
    2004 2832
    2005 3890
    2
    2002 2005
    2003 2005
    
    Expected output
    false
    true
    
  2. Example 2

    Input
    3
    1985 5782
    1995 3048
    2005 4890
    2
    1985 2005
    2005 2015
    
    Expected output
    maybe
    maybe