Weighing the stones

Time limit1sMemory limit256 MB

Summary
After each ranked stone is placed on pan 1 or pan 2, report whether pan 1 is heavier under every valid weight assignment, pan 2 is, or neither is certain.
Level

Medium7 of 10

Topics
Segment tree, Greedy, Prefix sum
Solved
No attempts yet

Problem

Seunghyun picked up NN stones and lined them up from the lightest to the heaviest. No two stones weigh the same. The lightest stone has rank 1, the second lightest has rank 2, and the heaviest has rank NN.

Seunghyun puts the stones on a two pan balance one at a time. The order of the stones and the pan each stone goes on are fixed in advance. He never tells you the actual weights, only the ranks.

Write a program that decides which way the balance tips after each stone is placed. Every weight is positive, and a stone of higher rank is heavier than a stone of lower rank. Any assignment of weights that respects those two conditions is possible. The balance tips toward pan 1 only if pan 1 is heavier under every possible assignment, and the same rule holds for pan 2. If the result depends on the assignment, or the two pans can weigh the same, the heavier side is not certain.

Input

The first line has the number of stones NN (1≤N≤1000001 \le N \le 100000). Each of the next NN lines has two integers RR (1≤R≤N1 \le R \le N) and SS (1≤S≤21 \le S \le 2). RR is the rank of the stone being placed and SS is the number of the pan it goes on. All values of RR are different, so each rank from 11 to NN appears exactly once.

Output

Print one line for each stone as it is placed. Print > if pan 1 is heavier, < if pan 2 is heavier, and ? if you cannot be sure which side is heavier.

Examples8

  1. Example 1

    Input
    5
    1 2
    3 1
    2 1
    4 2
    5 1
    
    Expected output
    <
    >
    >
    ?
    >
    
  2. Example 2

    Input
    1
    1 1
    
    Expected output
    >
    
  3. Example 3

    Input
    1
    1 2
    
    Expected output
    <
    
  4. Example 4

    Input
    3
    3 2
    2 1
    1 1
    
    Expected output
    <
    <
    ?
    
  5. Example 5

    Input
    4
    4 2
    3 1
    2 1
    1 2
    
    Expected output
    <
    <
    ?
    ?
    
  6. Example 6

    Input
    6
    1 1
    2 1
    3 1
    4 1
    5 1
    6 1
    
    Expected output
    >
    >
    >
    >
    >
    >
    
  7. Example 7

    Input
    8
    8 2
    7 1
    6 2
    5 1
    4 2
    3 1
    2 2
    1 1
    
    Expected output
    <
    <
    <
    <
    <
    <
    <
    <
    
  8. Example 8

    Input
    10
    5 1
    10 2
    1 1
    6 1
    2 2
    9 1
    3 2
    8 2
    4 1
    7 1
    
    Expected output
    >
    <
    ?
    ?
    ?
    ?
    ?
    ?
    ?
    ?