Under construction

Still being built. Things may change

Sloppy Acorn Classifier

Interview

Time limit1sMemory limit1024 MB

Summary
For each acorn, find the first hole it falls out of, given that the acorn shrinks by 1 after each hole it passes.
Level

Medium4 of 10

Topics
Array, Binary search
Solved
No attempts yet

Problem

A sloppy classifier is used to sort acorns by size.

The classifier is a tilted board with NN holes. The holes are numbered from 1 to NN, starting from the highest one. The size of hole ii is aia_i.

When an acorn is dropped into the classifier, it rolls past hole 1, then hole 2, and so on up to hole NN. The surface is rough, so the acorn shrinks by 1 after it passes each hole. For example, if an acorn has size 10 when it passes hole 1, its size is 9 when it passes hole 2. Likewise, an acorn that has passed hole 2 has size 8 when it passes hole 3.

An acorn falls into a hole when that hole's size is greater than or equal to the acorn's current size.

For each of the QQ acorns, write a program that finds the number of the hole it falls out of. Under the given constraints, every acorn can fall out of some hole, whatever its size.

Input

The first line contains the number of holes NN. The second line contains the sizes of the holes a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N, separated by spaces. The third line contains the number of acorns QQ. The fourth line contains the sizes of the acorns s1,s2,⋯ ,sQs_1, s_2, \cdots, s_Q, separated by spaces.

Output

For each acorn, print the number of the hole it falls out of, in the order the acorns are given. Separate the numbers with spaces.

Constraints

  • 1≤N≤1051 \le N \le 10^5
  • 1≤ai≤N1 \le a_i \le N
  • 1≤Q≤1051 \le Q \le 10^5
  • 1≤si≤N1 \le s_i \le N

Examples1

  1. Example 1

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