Under construction

Still being built. Things may change

DP (Small)

Interview

Time limit2sMemory limit1024 MB

Summary
For each queried problem, find the longest sequence ending at it where both the problem numbers and the difficulties strictly increase.
Level

Medium4 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

This problem differs from DP (Large) in the limits on the number of problems, the number of queries, and the difficulty values.

DP is short for DYNAMIC Porani.

DYNAMIC Porani likes to solve problems in a DYNAMIC way. A DYNAMIC solution means solving as many problems as possible while both the problem numbers and the difficulties increase.

During vacation, Porani received a list of recommended problems from a senior to improve his algorithm skills. Lazy Porani does not want to solve every problem. When the senior tells him to solve a certain problem, find how many problems he must solve in total to solve them DYNAMICally, including that problem.

Input

The first line contains two integers NN (1≤N≤30001 \le N \le 3000) and QQ (1≤Q≤N1 \le Q \le N), separated by a space.

The second line contains NN non-negative integers DiD_i (1≤i≤N1 \le i \le N; 0≤Di≤30000 \le D_i \le 3000), the difficulty of each problem in order of problem number, separated by spaces. Problem numbers are consecutive positive integers starting from 1.

From the third line, QQ lines follow, each containing a problem number AiA_i (1≤i≤Q1 \le i \le Q; 1≤Ai≤N1 \le A_i \le N) that the senior asked Porani to solve. The problem numbers in the queries are distinct.

Output

Print QQ lines. On line ii, print the number of problems Porani must solve for the ii-th instruction from the senior.

Examples1

  1. Example 1

    Input
    6 6
    1 2 3 4 3 2
    1
    2
    3
    4
    5
    6
    
    Expected output
    4
    4
    4
    4
    3
    2