A - Feet

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

1 フィートは 12 インチです。

A フィート B インチは、インチ換算で何インチですか?

制約

  • 1 \leq A \leq 8
  • 0 \leq B \leq 11
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

A B

出力

答えを 1 行に出力せよ。単位 (インチ) は省いて出力すること。


入力例 1

6 7

出力例 1

79

6 フィート 7 インチは、インチ換算で 6 \times 12 + 7 = 79 インチです。


入力例 2

4 11

出力例 2

59

4 フィート 11 インチは、インチ換算で 4 \times 12 + 11 = 59 インチです。


入力例 3

8 0

出力例 3

96

8 フィート 0 インチは、インチ換算で 8 \times 12 + 0 = 96 インチです。

Score : 100 points

Problem Statement

1 foot is 12 inches.

How many inches is A feet B inches?

Constraints

  • 1 \leq A \leq 8
  • 0 \leq B \leq 11
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A B

Output

Output the answer in one line. Omit the unit (inches).


Sample Input 1

6 7

Sample Output 1

79

6 feet 7 inches is 6 \times 12 + 7 = 79 inches.


Sample Input 2

4 11

Sample Output 2

59

4 feet 11 inches is 4 \times 12 + 11 = 59 inches.


Sample Input 3

8 0

Sample Output 3

96

8 feet 0 inches is 8 \times 12 + 0 = 96 inches.

B - Exponential or Quadratic

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

2^n \gt n^2 ですか?

制約

  • n1 以上 10^9 以下の整数

入力

入力は以下の形式で標準入力から与えられる。

n

出力

2^n \gt n^2 なら Yes を、そうでないなら No を出力せよ。


入力例 1

5

出力例 1

Yes

2^5=32,\ 5^2=25 より 2^n \gt n^2 であるため、Yes を出力します。


入力例 2

2

出力例 2

No

n=2 の場合 2^n=n^2=2^2 となり、故に 2^n \gt n^2 ではありません。よって No を出力します。


入力例 3

623947744

出力例 3

Yes

Score : 100 points

Problem Statement

Does 2^n \gt n^2 hold?

Constraints

  • n is an integer between 1 and 10^9 (inclusive).

Input

Input is given from Standard Input in the following format:

n

Output

If 2^n \gt n^2, print Yes; otherwise, print No.


Sample Input 1

5

Sample Output 1

Yes

Since 2^5=32,\ 5^2=25, we have 2^n \gt n^2, so Yes should be printed.


Sample Input 2

2

Sample Output 2

No

For n=2, we have 2^n=n^2=2^2, so 2^n \gt n^2 does not hold. Thus, No should be printed.


Sample Input 3

623947744

Sample Output 3

Yes
C - Qual B

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

あるプログラミングコンテストの予選に N 人が参加し、参加者全員が異なる順位を得ました。
長さ N の文字列 S が与えられ、この文字列は決勝への参加希望の有無を表現します。具体的には下記の通りです。

  • Si 文字目が o なら、予選 i 位の参加者が決勝への参加を希望した。
  • Si 文字目が x なら、予選 i 位の参加者が決勝への参加を希望しなかった。

決勝への参加を希望した参加者のうち順位の小さい方から K 人が予選を通過します。

以下の条件を満たす長さ N の文字列 T を出力してください。

  • 予選 i 位の参加者が予選を通過する場合、 Ti 文字目は o
  • 予選 i 位の参加者が予選を通過しない場合、 Ti 文字目は x

制約

  • N,K は整数
  • 1 \le K \le N \le 100
  • Sox からなる長さ N の文字列
  • S には少なくとも K 個の o が含まれる

入力

入力は以下の形式で標準入力から与えられる。

N K
S

出力

答えを出力せよ。


入力例 1

10 3
oxxoxooxox

出力例 1

oxxoxoxxxx

この入力の場合、予選の参加者は N=10 人であり、予選を通過する人数は K=3 人です。

  • 予選 1 位の参加者は決勝への参加を希望しているため、予選を通過します。この時点で、通過者は 1 人です。
  • 予選 2,3 位の参加者は決勝への参加を希望していないため、予選を通過しません。
  • 予選 4 位の参加者は決勝への参加を希望しているため、予選を通過します。この時点で、通過者は 2 人です。
  • 予選 5 位の参加者は決勝への参加を希望していないため、予選を通過しません。
  • 予選 6 位の参加者は決勝への参加を希望しているため、予選を通過します。この時点で、通過者は 3 人です。
  • ここで、予選を通過した人数が 3 人となりました。なので、予選 7 位以下の参加者は予選を通過しません。

Score : 200 points

Problem Statement

There were N contestants in the qualification round of a programming contest. All contestants got distinct ranks.
You are given a length-N string S, which represents whether the contestants want to participate in the final round or not. Specifically,

  • if the i-th character of S is o, the contestant ranked i-th in the qualification wants to participate in the final;
  • if the i-th character of S is x, the contestant ranked i-th in the qualification does not want to participate in the final.

Among those who want to participate in the final, K contestants with the smallest ranks advance to the final.

Print a string T of length N that satisfies the following conditions:

  • if the contestant ranked i-th in the qualification advances to the final, the i-th character of T is o;
  • if the contestant ranked i-th in the qualification does not advance to the final, the i-th character of T is x.

Constraints

  • N and K are integers.
  • 1 \le K \le N \le 100
  • S is a string of length N consisting of o and x.
  • S has at least K o's.

Input

The input is given from Standard Input in the following format:

N K
S

Output

Print the answer.


Sample Input 1

10 3
oxxoxooxox

Sample Output 1

oxxoxoxxxx

In this input, N=10 people took part in the qualification round, and K=3 of them advance to the final.

  • The participant who ranked 1-st in the qualification wants to participate in the final, so the participant advances to the final. 1 participant has advanced so far.
  • The participants who ranked 2-nd and 3-rd in the qualification do not want to participate in the final, so the participants do not advance to the final.
  • The participant who ranked 4-th in the qualification wants to participate in the final, so the participant advances to the final. 2 participants have advanced so far.
  • The participants who ranked 5-th in the qualification does not want to participate in the final, so the participant does not advance to the final.
  • The participant who ranked 6-th in the qualification wants to participate in the final, so the participant advances to the final. 3 participants have advanced so far.
  • Now that 3 people have advanced to the final, no participants ranked 7-th or lower advance to the final.
D - Rectangle Detection

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

高橋くんは、以下の方法で 10 個の文字列 S_1,S_2,\dots,S_{10} を生成しました。

  • まず、 S_i (1 \le i \le 10)= .......... ( .10 個並んだ文字列) とする。
  • 次に、以下の条件を全て満たす 4 つの整数 A,B,C,D を選ぶ。
    • 1 \le A \le B \le 10
    • 1 \le C \le D \le 10
  • その後、以下の条件を全て満たす全ての整数組 (i,j) について、 S_ij 文字目を # に書き換える。
    • A \le i \le B
    • C \le j \le D

以上の方法で生成された S_1,S_2,\dots,S_{10} が与えられるので、高橋くんが選んだ整数 A,B,C,D を求めてください。
なお、制約より A,B,C,D は一意に定まる (答えはただひとつ存在する) ことが証明できます。

制約

  • S_1,S_2,\dots,S_{10} は問題文中の方法で生成されうるそれぞれ長さ 10 の文字列

入力

入力は以下の形式で標準入力から与えられる。

S_1
S_2
\vdots
S_{10}

出力

答えを以下の形式で出力せよ。

A B
C D

入力例 1

..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

出力例 1

5 8
4 9

高橋くんが選んだ整数は A=5,B=8,C=4,D=9 です。
このように選ぶことにより、 S_5,S_6,S_7,S_84 文字目から 9 文字目が # であり他の文字が . である 10 個の長さ 10 の文字列 S_1,S_2,\dots,S_{10} が生成されます。
これは入力で与えられた 10 個の文字列と一致します。


入力例 2

..........
..#.......
..........
..........
..........
..........
..........
..........
..........
..........

出力例 2

2 2
3 3

入力例 3

##########
##########
##########
##########
##########
##########
##########
##########
##########
##########

出力例 3

1 10
1 10

Score : 200 points

Problem Statement

Takahashi generated 10 strings S_1,S_2,\dots,S_{10} as follows.

  • First, let S_i (1 \le i \le 10)= .......... (10 .s in a row).
  • Next, choose four integers A, B, C, and D satisfying all of the following.
    • 1 \le A \le B \le 10.
    • 1 \le C \le D \le 10.
  • Then, for every pair of integers (i,j) satisfying all of the following, replace the j-th character of S_i with #.
    • A \le i \le B.
    • C \le j \le D.

You are given S_1,S_2,\dots,S_{10} generated as above. Find the integers A, B, C, and D Takahashi chose.
It can be proved that such integers A, B, C, and D uniquely exist (there is just one answer) under the Constraints.

Constraints

  • S_1,S_2,\dots,S_{10} are strings, each of length 10, that can be generated according to the Problem Statement.

Input

The input is given from Standard Input in the following format:

S_1
S_2
\vdots
S_{10}

Output

Print the answer in the following format:

A B
C D

Sample Input 1

..........
..........
..........
..........
...######.
...######.
...######.
...######.
..........
..........

Sample Output 1

5 8
4 9

Here, Takahashi chose A=5, B=8, C=4, D=9.
This choice generates 10 strings S_1,S_2,\dots,S_{10}, each of length 10, where the 4-th through 9-th characters of S_5,S_6,S_7,S_8 are #, and the other characters are ..
These are equal to the strings given in the input.


Sample Input 2

..........
..#.......
..........
..........
..........
..........
..........
..........
..........
..........

Sample Output 2

2 2
3 3

Sample Input 3

##########
##########
##########
##########
##########
##########
##########
##########
##########
##########

Sample Output 3

1 10
1 10
E - Simple path

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

N 頂点の木 T があり、 i (1\leq i\leq N-1) 番目の辺は頂点 U_i と頂点 V_i を結んでいます。

T 上の相異なる 2 頂点 X,Y が与えられるので、 頂点 X から頂点 Y への単純パス上の頂点(端点含む)を順に列挙してください。

ただし、木上の任意の相異なる 2 頂点 a,b について、a から b への単純パスがただ一つ存在することが証明できます。

単純パスとは? グラフ G 上の頂点 X,Y に対して、頂点列 v_1,v_2, \ldots, v_k であって、 v_1=X, v_k=Y かつ、1\leq i\leq k-1 に対して v_iv_{i+1} が辺で結ばれているようなものを頂点 X から頂点 Y への パス と呼びます。 さらに、v_1,v_2, \ldots, v_k がすべて異なるようなものを頂点 X から頂点 Y への 単純パス と呼びます。

制約

  • 1\leq N\leq 2\times 10^5
  • 1\leq X,Y\leq N
  • X\neq Y
  • 1\leq U_i,V_i\leq N
  • 入力はすべて整数
  • 与えられるグラフは木

入力

入力は以下の形式で標準入力から与えられる。

N X Y
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}

出力

頂点 X から頂点 Y への単純パス上の頂点番号を順に空白区切りで出力せよ。


入力例 1

5 2 5
1 2
1 3
3 4
3 5

出力例 1

2 1 3 5

T は以下のような形であり、頂点 2 から頂点 5への単純パスは 頂点 2 \to 頂点 1 \to 頂点 3 \to 頂点 5 となります。
よって、2,1,3,5 をこの順に空白区切りで出力します。


入力例 2

6 1 2
3 1
2 5
1 2
4 1
2 6

出力例 2

1 2

T は以下のような形です。

Score : 300 points

Problem Statement

There is a tree T with N vertices. The i-th edge (1\leq i\leq N-1) connects vertex U_i and vertex V_i.

You are given two different vertices X and Y in T. List all vertices along the simple path from vertex X to vertex Y in order, including endpoints.

It can be proved that, for any two different vertices a and b in a tree, there is a unique simple path from a to b.

What is a simple path? For vertices X and Y in a graph G, a path from vertex X to vertex Y is a sequence of vertices v_1,v_2, \ldots, v_k such that v_1=X, v_k=Y, and v_i and v_{i+1} are connected by an edge for each 1\leq i\leq k-1. Additionally, if all of v_1,v_2, \ldots, v_k are distinct, the path is said to be a simple path from vertex X to vertex Y.

Constraints

  • 1\leq N\leq 2\times 10^5
  • 1\leq X,Y\leq N
  • X\neq Y
  • 1\leq U_i,V_i\leq N
  • All values in the input are integers.
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

N X Y
U_1 V_1
U_2 V_2
\vdots
U_{N-1} V_{N-1}

Output

Print the indices of all vertices along the simple path from vertex X to vertex Y in order, with spaces in between.


Sample Input 1

5 2 5
1 2
1 3
3 4
3 5

Sample Output 1

2 1 3 5

The tree T is shown below. The simple path from vertex 2 to vertex 5 is 2 \to 1 \to 3 \to 5.
Thus, 2,1,3,5 should be printed in this order, with spaces in between.


Sample Input 2

6 1 2
3 1
2 5
1 2
4 1
2 6

Sample Output 2

1 2

The tree T is shown below.

F - Route Map

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

AtCoder 鉄道のとある路線には N 個の駅が存在し、始点から終点に向かって i \, (1 \leq i \leq N) 番目の駅の名前は S_i です。

普通列車は全ての駅に止まりますが、急行列車は全ての駅に止まるとは限りません。具体的には、急行列車は M \, (M \leq N) 個の駅にのみ止まり、j \, (1 \leq j \leq M) 番目に止まる駅の名前は T_j です。
ただし、T_1 = S_1 かつ T_M = S_N、すなわち急行列車は始点と終点の両方に止まることが保証されます。

N 個の駅それぞれについて、その駅に急行列車が止まるかどうか判定してください。

制約

  • 2 \leq M \leq N \leq 10^5
  • N, M は整数
  • S_i \, (1 \leq i \leq N) は英小文字のみからなる 1 文字以上 10 文字以下の文字列
  • S_i \neq S_j \, (i \neq j)
  • T_1 = S_1 かつ T_M = S_N
  • (T_1, \dots, T_M)(S_1, \dots, S_N) から 0 個以上の文字列を選んで取り除き、残った文字列を元の順序で並べることで得られる

入力

入力は以下の形式で標準入力から与えられる。

N M
S_1 \ldots S_N
T_1 \ldots T_M

出力

N 行出力せよ。i \, (1 \leq i \leq N) 行目には、始点から終点に向かって i 番目の駅に急行列車が止まるなら Yes、そうでないなら No と出力せよ。


入力例 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

出力例 1

Yes
No
Yes
No
Yes

入力例 2

7 7
a t c o d e r
a t c o d e r

出力例 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

急行列車が全ての駅に止まることもあります。

Score : 300 points

Problem Statement

There are N stations on a certain line operated by AtCoder Railway. The i-th station (1 \leq i \leq N) from the starting station is named S_i.

Local trains stop at all stations, while express trains may not. Specifically, express trains stop at only M \, (M \leq N) stations, and the j-th stop (1 \leq j \leq M) is the station named T_j.
Here, it is guaranteed that T_1 = S_1 and T_M = S_N, that is, express trains stop at both starting and terminal stations.

For each of the N stations, determine whether express trains stop at that station.

Constrains

  • 2 \leq M \leq N \leq 10^5
  • N and M are integers.
  • S_i (1 \leq i \leq N) is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • S_i \neq S_j \, (i \neq j)
  • T_1 = S_1 and T_M = S_N.
  • (T_1, \dots, T_M) is obtained by removing zero or more strings from (S_1, \dots, S_N) and lining up the remaining strings without changing the order.

Input

Input is given from Standard Input in the following format:

N M
S_1 \ldots S_N
T_1 \ldots T_M

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain Yes if express trains stop at the i-th station from the starting station, and No otherwise.


Sample Input 1

5 3
tokyo kanda akiba okachi ueno
tokyo akiba ueno

Sample Output 1

Yes
No
Yes
No
Yes

Sample Input 2

7 7
a t c o d e r
a t c o d e r

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes
Yes

Express trains may stop at all stations.

G - Peaceful Teams

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

N 人のスポーツ選手がいます。

N 人の選手たちには互いに相性の悪い選手のペアが M 組あり、相性の悪い組のうち i\ (1\leq i\leq M) 組目は A _ i 番目の選手と B _ i 番目の選手です。

あなたは、選手を T チームに分けます。 どの選手もちょうど一つのチームに属さなければならず、どのチームにも少なくとも一人の選手が属さなければなりません。 さらに、どの i=1,2,\ldots,M についても、 A _ i 番目の選手と B _ i 番目の選手が同じチームに属していてはいけません。

この条件を満たすチーム分けの方法は何通りあるか求めてください。 ただし、チーム分けの方法が異なるとは、ある二人が存在して、彼らが一方のチーム分けでは同じチームに所属し、もう一方では異なるチームに所属することをいいます。

制約

  • 1\leq T\leq N\leq10
  • 0\leq M\leq\dfrac{N(N-1)}2
  • 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
  • (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N T M
A _ 1 B _ 1
A _ 2 B _ 2
\vdots
A _ M B _ M

出力

答えを 1 行で出力せよ。


入力例 1

5 2 2
1 3
3 4

出力例 1

4

次の 4 通りのチーム分けが条件を満たします。

他に条件を満たすチーム分けは存在しないので、4 を出力してください。


入力例 2

5 1 2
1 3
3 4

出力例 2

0

条件を満たすチーム分けがひとつも存在しないこともあります。


入力例 3

6 4 0

出力例 3

65

相性の悪いペアがひとつも存在しないこともあります。


入力例 4

10 6 8
5 9
1 4
3 8
1 6
4 10
5 7
5 6
3 7

出力例 4

8001

Score : 400 points

Problem Statement

There are N sports players.

Among them, there are M incompatible pairs. The i-th incompatible pair (1\leq i\leq M) is the A_i-th and B_i-th players.

You will divide the players into T teams. Every player must belong to exactly one team, and every team must have one or more players. Additionally, for each i=1,2,\ldots,M, the A_i-th and B_i-th players must not belong to the same team.

Find the number of ways to satisfy these conditions. Here, two divisions are considered different when there are two players who belong to the same team in one division and different teams in the other.

Constraints

  • 1\leq T\leq N\leq10
  • 0\leq M\leq\dfrac{N(N-1)}2
  • 1\leq A _ i\lt B _ i\leq N\ (1\leq i\leq M)
  • (A _ i,B _ i)\neq (A _ j,B _ j)\ (1\leq i\lt j\leq M)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N T M
A _ 1 B _ 1
A _ 2 B _ 2
\vdots
A _ M B _ M

Output

Print the answer in a single line.


Sample Input 1

5 2 2
1 3
3 4

Sample Output 1

4

The following four divisions satisfy the conditions.

No other division satisfies them, so print 4.


Sample Input 2

5 1 2
1 3
3 4

Sample Output 2

0

There may be no division that satisfies the conditions.


Sample Input 3

6 4 0

Sample Output 3

65

There may be no incompatible pair.


Sample Input 4

10 6 8
5 9
1 4
3 8
1 6
4 10
5 7
5 6
3 7

Sample Output 4

8001
H - Lucky Numbers

実行時間制限: 4 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

長さ N-1 の整数列 S = (S_1, S_2, \ldots, S_{N-1}) および、「ラッキーナンバー」として M 個の相異なる整数 X_1, X_2, \ldots, X_M が与えられます。

長さ N の整数列 A = (A_1, A_2, \ldots, A_N) であって、次の条件を満たすものを「良い数列」と呼びます。

すべての i = 1, 2, \ldots, N-1 について、A_i + A_{i+1} = S_i が成り立つ。

良い数列 A1 つ選ぶときの、A の要素のうちラッキーナンバーであるものの個数(すなわち、A_i \in \lbrace X_1, X_2, \ldots, X_M \rbrace となる 1 以上 N 以下の整数 i の個数)としてあり得る最大値を求めてください。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10
  • -10^9 \leq S_i \leq 10^9
  • -10^9 \leq X_i \leq 10^9
  • X_1 \lt X_2 \lt \cdots \lt X_M
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M
S_1 S_2 \ldots S_{N-1}
X_1 X_2 \ldots X_M

出力

良い数列 A1 つ選ぶときの、A の要素のうちラッキーナンバーであるものの個数としてありうる最大値を出力せよ。


入力例 1

9 2
2 3 3 4 -4 -7 -4 -1
-1 5

出力例 1

4

良い数列 A として A = (3, -1, 4, -1, 5, -9, 2, -6, 5) を選ぶと、A の要素のうちラッキーナンバーであるものは A_2, A_4, A_5, A_94 個となり、これが考えられる中で最大です。


入力例 2

20 10
-183260318 206417795 409343217 238245886 138964265 -415224774 -499400499 -313180261 283784093 498751662 668946791 965735441 382033304 177367159 31017484 27914238 757966050 878978971 73210901
-470019195 -379631053 -287722161 -231146414 -84796739 328710269 355719851 416979387 431167199 498905398

出力例 2

8

Score : 500 points

Problem Statement

You are given a sequence of N-1 integers S = (S_1, S_2, \ldots, S_{N-1}), and M distinct integers X_1, X_2, \ldots, X_M, which are called lucky numbers.

A sequence of N integers A = (A_1, A_2, \ldots, A_N) satisfying the following condition is called a good sequence.

A_i + A_{i+1} = S_i holds for every i = 1, 2, \ldots, N-1.

Find the maximum possible number of terms that are lucky numbers in a good sequence A, that is, the maximum possible number of integers i between 1 and N such that A_i \in \lbrace X_1, X_2, \ldots, X_M \rbrace.

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq M \leq 10
  • -10^9 \leq S_i \leq 10^9
  • -10^9 \leq X_i \leq 10^9
  • X_1 \lt X_2 \lt \cdots \lt X_M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
S_1 S_2 \ldots S_{N-1}
X_1 X_2 \ldots X_M

Output

Print the maximum possible number of terms that are lucky numbers in a good sequence A.


Sample Input 1

9 2
2 3 3 4 -4 -7 -4 -1
-1 5

Sample Output 1

4

A good sequence A = (3, -1, 4, -1, 5, -9, 2, -6, 5) contains four terms that are lucky numbers: A_2, A_4, A_5, A_9, which is the maximum possible count.


Sample Input 2

20 10
-183260318 206417795 409343217 238245886 138964265 -415224774 -499400499 -313180261 283784093 498751662 668946791 965735441 382033304 177367159 31017484 27914238 757966050 878978971 73210901
-470019195 -379631053 -287722161 -231146414 -84796739 328710269 355719851 416979387 431167199 498905398

Sample Output 2

8
I - Prefix LIS Query

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。

Q 個のクエリを処理してください。 i\ (1\leq i\leq Q) 番目のクエリは以下の通りです:

  • 整数 R_i,X_i が与えられる。数列 (A_1,A_2,\dots,A_{R_i}) の(連続とは限らない)部分列であって、狭義単調増加であり、かつ全ての要素が X_i 以下であるようなものの長さの最大値を求めよ。 なお、X_i \geq \min\lbrace A_1, A_2,\dots,A_{R_i} \rbrace が保証される。

制約

  • 1\leq N,Q \leq 2\times 10^5
  • 1\leq A_i \leq 10^9
  • 1\leq R_i\leq N
  • \min\lbrace A_1, A_2,\dots,A_{R_i} \rbrace\leq X_i\leq 10^9
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
A_1 A_2 \dots A_N
R_1 X_1
R_2 X_2
\vdots
R_Q X_Q

出力

Q 行出力せよ。 i\ (1\leq i \leq Q) 行目には、i 番目のクエリに対する答えを出力せよ。


入力例 1

5 3
2 4 1 3 3
2 5
5 2
5 3

出力例 1

2
1
2
  • 1 番目のクエリ:数列 (2,4) の狭義単調増加な部分列であって、全ての要素が 5 以下であるようなものの長さの最大値は 2 です。
    具体的には、部分列 (2,4) が該当します。
  • 2 番目のクエリ:数列 (2,4,1,3,3) の狭義単調増加な部分列であって、全ての要素が 2 以下であるようなものの長さの最大値は 1 です。
    具体的には、部分列 (2) および (1) が該当します。
  • 3 番目のクエリ:数列 (2,4,1,3,3) の狭義単調増加な部分列であって、全ての要素が 3 以下であるようなものの長さの最大値は 2 です。
    具体的には、部分列 (2,3) および (1,3) が該当します。

入力例 2

10 8
2 5 6 5 2 1 7 9 7 2
7 8
5 2
2 3
2 6
7 3
8 9
9 6
8 7

出力例 2

4
1
1
2
1
5
3
4

Score : 500 points

Problem Statement

You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.

Answer Q queries. The i-th query (1 \leq i \leq Q) is as follows:

  • You are given integers R_i and X_i. Consider a subsequence (not necessarily contiguous) of (A_1, A_2, \dots, A_{R_i}) that is strictly increasing and consists only of elements at most X_i. Find the maximum possible length of such a subsequence. It is guaranteed that X_i \geq \min\lbrace A_1, A_2,\dots,A_{R_i} \rbrace.

Constraints

  • 1 \leq N,Q \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq R_i \leq N
  • \min\lbrace A_1, A_2,\dots,A_{R_i} \rbrace\leq X_i\leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N Q
A_1 A_2 \dots A_N
R_1 X_1
R_2 X_2
\vdots
R_Q X_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.


Sample Input 1

5 3
2 4 1 3 3
2 5
5 2
5 3

Sample Output 1

2
1
2
  • 1st query: For the sequence (2,4), the longest strictly increasing subsequence with all elements at most 5 has length 2.
    Specifically, (2,4) qualifies.
  • 2nd query: For the sequence (2,4,1,3,3), the longest strictly increasing subsequence with all elements at most 2 has length 1.
    Specifically, (2) and (1) qualify.
  • 3rd query: For the sequence (2,4,1,3,3), the longest strictly increasing subsequence with all elements at most 3 has length 2.
    Specifically, (2,3) and (1,3) qualify.

Sample Input 2

10 8
2 5 6 5 2 1 7 9 7 2
7 8
5 2
2 3
2 6
7 3
8 9
9 6
8 7

Sample Output 2

4
1
1
2
1
5
3
4