This page is still under construction.

Parts of this page are still being built. What you see may change.

Video Clips

Time limit2sMemory limit1024 MB

Summary
For each starting video index, find which video a viewer reaches after watching M videos, where the next video after i is S[i].
Level

Medium6 of 10

Topics
Graph, Binary search, Implementation, Array
Solved
No attempts yet

Problem

On a popular web site, the NN KATT contestants watch cat videos between solving problems.

The site has KK videos of cats jumping around on a keyboard, numbered from 00 to K−1K - 1. When a contestant finishes a video, the site suggests the next cat video, and the contestant of course clicks it and starts watching.

You are given the cat video each contestant watches first. Find the MM-th video each contestant watches.

Input

The judge reads input in the following format:

  • line 11: K M
  • line 22: S[0] ... S[K - 1]
  • line 33: N: the number of calls made to clip(I).
  • line 44: I1 ... IN: the parameters of the NN calls to clip(I).

Output

The judge writes NN lines with the return values of clip(I).

Constraints

  • N,K≤100 000N, K \le 100\,000
  • 2≤M≤1092 \le M \le 10^9

Examples1

  1. Example 1

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