A - First Grid

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

配点 : 100

問題文

2 行、横 2 列のグリッド(各マスが正方形のマス目)があります。
このグリッドは、各マスが黒か白であり、少なくとも 2 つの黒マスを含みます。
各マスの色の情報は文字列 S_1,S_2 として、以下の形式で与えられます。

  • 文字列 S_ij 文字目が # であれば上から i マス目、左から j マス目は黒
  • 文字列 S_ij 文字目が . であれば上から i マス目、左から j マス目は白

2 つの異なる黒マス同士が辺で接している時、またその時に限りそれら 2 つの黒マスは直接行き来できます。
黒マスのみをいくつか通ることによって、どの 2 つの黒マス同士も(直接または間接的に)行き来できるかどうか判定してください。

制約

  • S_1,S_2# または . からなる 2 文字の文字列
  • S_1,S_2# が合計で 2 つ以上含まれる

入力

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

S_1
S_2

出力

どの 2 つの黒マス同士も行き来できるなら Yes 、そうでないなら No と出力せよ。


入力例 1

##
.#

出力例 1

Yes

左上の黒マスと右上の黒マス、右上の黒マスと右下の黒マスを直接行き来することができます。
これらの移動を用いてどの黒マスからどの黒マスへも行き来できるので、答えは Yes となります。


入力例 2

.#
#.

出力例 2

No

右上の黒マスと左下の黒マスを行き来することはできません。答えは No となります。

Score : 100 points

Problem Statement

We have a grid with 2 horizontal rows and 2 vertical columns.
Each of the squares is black or white, and there are at least 2 black squares.
The colors of the squares are given to you as strings S_1 and S_2, as follows.

  • If the j-th character of S_i is #, the square at the i-th row from the top and j-th column from the left is black.
  • If the j-th character of S_i is ., the square at the i-th row from the top and j-th column from the left is white.

You can travel between two different black squares if and only if they share a side.
Determine whether it is possible to travel from every black square to every black square (directly or indirectly) by only passing black squares.

Constraints

  • Each of S_1 and S_2 is a string with two characters consisting of # and ..
  • S_1 and S_2 have two or more #s in total.

Input

Input is given from Standard Input in the following format:

S_1
S_2

Output

If it is possible to travel from every black square to every black square, print Yes; otherwise, print No.


Sample Input 1

##
.#

Sample Output 1

Yes

It is possible to directly travel between the top-left and top-right black squares and between top-right and bottom-right squares.
These two moves enable us to travel from every black square to every black square, so the answer is Yes.


Sample Input 2

.#
#.

Sample Output 2

No

It is impossible to travel between the top-right and bottom-left black squares, so the answer is No.

B - Legendary Players

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

配点 : 100

問題文

AtCoder では、レーティング上位 10 人のハンドルネームには金色の冠が、上位 1 人のハンドルネームには白金色の冠が表示されます。

このコンテストが開始した時点で、アルゴリズム部門での上位 10 人に入っているプレイヤーのハンドルネームとレーティングは以下のようになっています。

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

上記のプレイヤーのハンドルネーム S が与えられるので、その人のレーティングを出力してください。

制約

  • S はアルゴリズム部門でレーティング上位 10 人に入っているプレイヤーのハンドルネームのいずれかと等しい。

入力

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

S

出力

対応するプレイヤーのレーティングを 1 行で出力せよ。


入力例 1

tourist

出力例 1

3858

このコンテストが開始した時点において、 tourist さんのアルゴリズム部門のレーティングは 3858 です。


入力例 2

semiexp

出力例 2

3481

このコンテストが開始した時点において、 semiexp さんのアルゴリズム部門のレーティングは 3481 です。

Score : 100 points

Problem Statement

In AtCoder, the top 10 rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.

At the start of this contest, the usernames and ratings of the top 10 rated players in the algorithm category are as follows:

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

You are given the username S of one of these players. Print that player's rating.

Constraints

  • S is equal to one of the usernames of the top 10 rated players in the algorithm category.

Input

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

S

Output

Print the rating of the corresponding player in one line.


Sample Input 1

tourist

Sample Output 1

3858

At the start of this contest, the rating of tourist in the algorithm category is 3858.


Sample Input 2

semiexp

Sample Output 2

3481

At the start of this contest, the rating of semiexp in the algorithm category is 3481.

C - Matrix Transposition

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

配点 : 200

問題文

HW 列の行列 A が与えられます。
A の上から i 行目、左から j 列目の要素は A_{i,j} です。

ここで、WH 列の行列 B を、上から i 行目、左から j 列目の要素が A_{j,i} と一致するような行列として定めます。
すなわち、BA の転置行列です。

B を出力してください。

制約

  • 1\leq H,W \leq 10^5
  • H \times W \leq 10^5
  • 1 \leq A_{i,j} \leq 10^9
  • 入力は全て整数である

入力

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

H W
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

出力

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

B_{1,1} B_{1,2} \ldots B_{1,H}
B_{2,1} B_{2,2} \ldots B_{2,H}
\vdots
B_{W,1} B_{W,2} \ldots B_{W,H}

入力例 1

4 3
1 2 3
4 5 6
7 8 9
10 11 12

出力例 1

1 4 7 10
2 5 8 11
3 6 9 12

たとえば A_{2,1}=4 なので、転置行列 B の上から 1 行目、左から 2 列目の要素は 4 になります。


入力例 2

2 2
1000000000 1000000000
1000000000 1000000000

出力例 2

1000000000 1000000000
1000000000 1000000000

Score : 200 points

Problem Statement

You are given an H-by-W matrix A.
The element at the i-th row from the top and j-th column from the left of A is A_{i,j}.

Let B be a W-by-H matrix whose element at the i-th row from the top and j-th column from the left equals A_{j, i}.
That is, B is the transpose of A.

Print B.

Constraints

  • 1\leq H,W \leq 10^5
  • H \times W \leq 10^5
  • 1 \leq A_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

Output

Print B in the following format:

B_{1,1} B_{1,2} \ldots B_{1,H}
B_{2,1} B_{2,2} \ldots B_{2,H}
\vdots
B_{W,1} B_{W,2} \ldots B_{W,H}

Sample Input 1

4 3
1 2 3
4 5 6
7 8 9
10 11 12

Sample Output 1

1 4 7 10
2 5 8 11
3 6 9 12

For example, we have A_{2,1}=4, so the element at the 1-st row from the top and 2-nd column from the left of the transpose B is 4.


Sample Input 2

2 2
1000000000 1000000000
1000000000 1000000000

Sample Output 2

1000000000 1000000000
1000000000 1000000000
D - mpp

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

配点 : 200

問題文

英小文字からなる文字列 S が与えられます。 S の中で出現回数が最も多い文字をすべて取り除き、残った文字を元の順序を保ったまま連結して出力してください。

なお、出現回数が最大の文字が複数種類ある場合は、そのすべてを取り除いてください。

制約

  • 1 \le |S| \le 100
  • S は英小文字からなる文字列である

入力

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

S

出力

答えを出力せよ。


入力例 1

mississippi

出力例 1

mpp

mississippi に最も多く出現する文字は si でともに 4 回出現します。si をすべて取り除いた文字列は mpp となります。


入力例 2

atcoder

出力例 2



入力例 3

beginner

出力例 3

bgir

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Remove all occurrences of the most frequent character(s) in S, then output the remaining characters concatenated in their original order.

If there are multiple characters with the maximum frequency, remove all of them.

Constraints

  • 1 \le |S| \le 100
  • S is a string consisting of lowercase English letters.

Input

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

S

Output

Output the answer.


Sample Input 1

mississippi

Sample Output 1

mpp

The most frequent characters in mississippi are s and i, each appearing four times. Removing all occurrences of s and i yields the string mpp.


Sample Input 2

atcoder

Sample Output 2



Sample Input 3

beginner

Sample Output 3

bgir
E - Not All Covered

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

配点 : 300

問題文

AtCoder 王国には 1 から N まで番号がつけられた N 個の城壁があります。また、 M 個の砲台があります。

砲台 iL_i 以上 R_i 以下の番号の城壁を守っています。

ある砲台を破壊すると、その砲台が守っていた城壁はその砲台により守られなくなります。

どの砲台にも守られていない城壁が存在する状態にするためには、最小で何個の砲台を破壊する必要がありますか?

制約

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
  • 入力はすべて整数

入力

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

N M
L_1 R_1
L_2 R_2
 \vdots 
L_M R_M

出力

砲台に守られていない城壁が存在する状態にするために破壊する必要がある砲台の個数の最小値を出力せよ。


入力例 1

10 4
1 6
4 5
5 10
7 10

出力例 1

1

砲台 1 を破壊するとどの砲台も城壁 3 を守っていない状態になります。 また、砲台を 1 個も破壊しなければ全ての城壁がどれかの砲台に守られている状態になります。 そのため、1 を出力します。


入力例 2

5 2
1 2
3 4

出力例 2

0

どの砲台も城壁 5 を守っていないため、砲台を 1 個も破壊しないでも砲台に守られていない城壁が存在する状態になります。そのため、0 を出力します。


入力例 3

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

出力例 3

3

Score : 300 points

Problem Statement

In the AtCoder Kingdom, there are N castle walls numbered from 1 through N. There are also M turrets.

Turret i guards castle walls numbered from L_i through R_i.

When a turret is destroyed, the castle walls that were guarded by that turret are no longer guarded by that turret.

What is the minimum number of turrets that need to be destroyed so that at least one castle wall is not guarded by any turret?

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
  • All input values are integers.

Input

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

N M
L_1 R_1
L_2 R_2
 \vdots 
L_M R_M

Output

Output the minimum number of turrets that need to be destroyed so that at least one castle wall is not guarded by any turret.


Sample Input 1

10 4
1 6
4 5
5 10
7 10

Sample Output 1

1

If turret 1 is destroyed, no turret guards castle wall 3. Also, if no turrets are destroyed, all castle walls are guarded by some turret. Therefore, output 1.


Sample Input 2

5 2
1 2
3 4

Sample Output 2

0

Since no turret guards castle wall 5, there already exists a castle wall not guarded by any turret without destroying any turrets. Therefore, output 0.


Sample Input 3

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

Sample Output 3

3
F - Monotonically Increasing

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

配点 : 300

問題文

長さ N かつ全ての要素が 1 以上 M 以下である整数列のうち、狭義単調増加であるものを全て辞書順に出力してください。

注記

ある 2 個の異なる長さの等しい整数列 A_1,A_2,\dots,A_NB_1,B_2,\dots,B_N が以下を満たすとき、またその時に限り辞書順で AB より早いと定義されます。

  • ある整数 i(1 \le i \le N) が存在し、1 \le j < i である全ての整数 j に対し A_j=B_j が成り立ち、かつ A_i < B_i が成り立つ。

ある整数列 A_1,A_2,\dots,A_N は以下を満たすとき、またその時に限り狭義単調増加です。

  • 全ての整数 i(1 \le i \le N-1) に対し A_i < A_{i+1} が成り立つ。

制約

  • 1 \le N \le M \le 10
  • 入力は全て整数。

入力

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

N M

出力

条件を満たす整数列を一行に一つずつ、辞書順に出力せよ(出力例を参考にせよ)。


入力例 1

2 3

出力例 1

1 2 
1 3 
2 3 

条件を満たす数列は (1,2),(1,3),(2,3)3 個です。これらを辞書順で早い方から出力します。


入力例 2

3 5

出力例 2

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

Score : 300 points

Problem Statement

Print all strictly increasing integer sequences of length N where all elements are between 1 and M (inclusive), in lexicographically ascending order.

Notes

For two integer sequences of the same length A_1,A_2,\dots,A_N and B_1,B_2,\dots,B_N, A is said to be lexicographically earlier than B if and only if:

  • there is an integer i (1 \le i \le N) such that A_j=B_j for all integers j satisfying 1 \le j < i, and A_i < B_i.

An integer sequence A_1,A_2,\dots,A_N is said to be strictly increasing if and only if:

  • A_i < A_{i+1} for all integers i (1 \le i \le N-1).

Constraints

  • 1 \le N \le M \le 10
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the sought sequences in lexicographically ascending order, each in its own line (see Sample Outputs).


Sample Input 1

2 3

Sample Output 1

1 2 
1 3 
2 3 

The sought sequences are (1,2),(1,3),(2,3), which should be printed in lexicographically ascending order.


Sample Input 2

3 5

Sample Output 2

1 2 3 
1 2 4 
1 2 5 
1 3 4 
1 3 5 
1 4 5 
2 3 4 
2 3 5 
2 4 5 
3 4 5 
G - Logical Filling

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

配点 : 400

問題文

., o, ? のみからなる長さ N の文字列 S が与えられます。 全ての ? をそれぞれ . または o で置き換えて得られる文字列のうち、以下の条件を全て満たすものの集合を X とします。

  • o の個数がちょうど K
  • o が連続しない

X が空集合でないことは保証されます。

以下を満たす、長さ N の文字列 T を出力して下さい。ここで、T の左から i 番目の文字を T_i と表記します。

  • X に含まれる全ての文字列の i 文字目が . である場合: T_i= .
  • X に含まれる全ての文字列の i 文字目が o である場合: T_i= o
  • i 文字目が . である文字列も o である文字列も X に含まれている場合: T_i=?

制約

  • 1\leq N\leq 2\times 10^5
  • 0\leq K
  • S., o, ? のみからなる長さ N の文字列
  • X は空集合ではない
  • 入力される数値は全て整数

入力

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

N K
S

出力

答えを出力せよ。


入力例 1

4 2
o???

出力例 1

o.??

o.o.o..o の二つの文字列から X はなります。

X に含まれる全ての文字列の 1 文字目は o なので、 T_1o です。

X に含まれる全ての文字列の 2 文字目は . なので、 T_2. です。

X に含まれる文字列の 3 文字目としては .o も考えられるので、 T_3? です。


入力例 2

5 2
?????

出力例 2

?????

入力例 3

7 3
.o???o.

出力例 3

.o.o.o.

Score : 400 points

Problem Statement

You are given a string S of length N consisting of the characters ., o, and ?. Among the strings that can be obtained by replacing every ? in S independently with either . or o, let X be the set of strings that satisfy all of the following conditions:

  • The number of os is exactly K.
  • No two os are adjacent.

It is guaranteed that X is non‑empty.

Print a string T of length N that satisfies the following (let T_i denote the i‑th character of T):

  • If the i‑th character of every string in X is ., then T_i= ..
  • If the i‑th character of every string in X is o, then T_i= o.
  • If X contains both a string whose i‑th character is . and a string whose i‑th character is o, then T_i= ?.

Constraints

  • 1 \le N \le 2 \times 10^{5}
  • 0 \le K
  • S is a string of length N consisting of ., o, ?.
  • X is non‑empty.
  • All given numerical values are integers.

Input

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

N K
S

Output

Print the answer.


Sample Input 1

4 2
o???

Sample Output 1

o.??

The set X consists of the two strings o.o. and o..o.

  • The 1st character of every string in X is o, so T_1 is o.
  • The 2nd character of every string in X is ., so T_2 is ..
  • The 3rd character of a string in X can be either . or o, so T_3 is ?.

Sample Input 2

5 2
?????

Sample Output 2

?????

Sample Input 3

7 3
.o???o.

Sample Output 3

.o.o.o.
H - Best Performances

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

配点 : 475

問題文

長さ N の数列 A=(A_1,A_2,\dots,A_N) があり、最初全ての項が 0 です。
入力で与えられる整数 K を用いて関数 f(A) を以下のように定義します。

  • A を降順に (広義単調減少となるように) ソートしたものを B とする。
  • このとき、 f(A)=B_1 + B_2 + \dots + B_K とする。

この数列に合計 Q 回の更新を行うことを考えます。
数列 A に対し以下の更新を i=1,2,\dots,Q の順に行い、各更新ごとにその時点での f(A) の値を出力してください。

  • A_{X_i}Y_i に変更する。

制約

  • 入力は全て整数
  • 1 \le K \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le X_i \le N
  • 0 \le Y_i \le 10^9

入力

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

N K Q
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

出力

全体で Q 行出力せよ。そのうち i 行目には i 回目の更新を終えた時点での f(A) の値を整数として出力せよ。


入力例 1

4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0

出力例 1

5
6
8
8
15
13
13
11
1
0

この入力では N=4,K=2 です。 Q=10 回の更新を行います。

  • 1 回目の更新を受けて A=(5,0,0,0) となります。このとき f(A)=5 です。
  • 2 回目の更新を受けて A=(5,1,0,0) となります。このとき f(A)=6 です。
  • 3 回目の更新を受けて A=(5,1,3,0) となります。このとき f(A)=8 です。
  • 4 回目の更新を受けて A=(5,1,3,2) となります。このとき f(A)=8 です。
  • 5 回目の更新を受けて A=(5,10,3,2) となります。このとき f(A)=15 です。
  • 6 回目の更新を受けて A=(0,10,3,2) となります。このとき f(A)=13 です。
  • 7 回目の更新を受けて A=(0,10,3,0) となります。このとき f(A)=13 です。
  • 8 回目の更新を受けて A=(0,10,1,0) となります。このとき f(A)=11 です。
  • 9 回目の更新を受けて A=(0,0,1,0) となります。このとき f(A)=1 です。
  • 10 回目の更新を受けて A=(0,0,0,0) となります。このとき f(A)=0 です。

Score : 475 points

Problem Statement

We have a sequence A=(A_1,A_2,\dots,A_N) of length N. Initially, all the terms are 0.
Using an integer K given in the input, we define a function f(A) as follows:

  • Let B be the sequence obtained by sorting A in descending order (so that it becomes monotonically non-increasing).
  • Then, let f(A)=B_1 + B_2 + \dots + B_K.

We consider applying Q updates on this sequence.
Apply the following operation on the sequence A for i=1,2,\dots,Q in this order, and print the value f(A) at that point after each update.

  • Change A_{X_i} to Y_i.

Constraints

  • All input values are integers.
  • 1 \le K \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le X_i \le N
  • 0 \le Y_i \le 10^9

Input

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

N K Q
X_1 Y_1
X_2 Y_2
\vdots
X_Q Y_Q

Output

Print Q lines in total. The i-th line should contain the value f(A) as an integer when the i-th update has ended.


Sample Input 1

4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0

Sample Output 1

5
6
8
8
15
13
13
11
1
0

In this input, N=4 and K=2. Q=10 updates are applied.

  • The 1-st update makes A=(5, 0,0,0). Now, f(A)=5.
  • The 2-nd update makes A=(5, 1,0,0). Now, f(A)=6.
  • The 3-rd update makes A=(5, 1,3,0). Now, f(A)=8.
  • The 4-th update makes A=(5, 1,3,2). Now, f(A)=8.
  • The 5-th update makes A=(5,10,3,2). Now, f(A)=15.
  • The 6-th update makes A=(0,10,3,2). Now, f(A)=13.
  • The 7-th update makes A=(0,10,3,0). Now, f(A)=13.
  • The 8-th update makes A=(0,10,1,0). Now, f(A)=11.
  • The 9-th update makes A=(0, 0,1,0). Now, f(A)=1.
  • The 10-th update makes A=(0, 0,0,0). Now, f(A)=0.
I - Rearrange Query

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

配点 : 500

問題文

長さ N の正整数列 A=(A_1,A_2,\ldots,A_N), B=(B_1,B_2,\ldots,B_N) が与えられます。

Q 個のクエリが与えられるので順に処理してください。i 番目のクエリは以下で説明されます。

  • 正整数 l_i,r_i,L_i,R_i が与えられる。数列 (A_{l_i},A_{l_i+1},\ldots,A_{r_i}) を並び替えることで (B_{L_i},B_{L_i+1},\ldots,B_{R_i}) に一致させることができるならば Yes を、できないならば No を出力せよ。

制約

  • 1\leq N,Q\leq 2\times 10^5
  • 1\leq A_i,B_i\leq N
  • 1\leq l_i \leq r_i\leq N
  • 1\leq L_i \leq R_i\leq N
  • 入力は全て整数

入力

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

N Q
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
l_1 r_1 L_1 R_1
l_2 r_2 L_2 R_2
\vdots
l_Q r_Q L_Q R_Q

出力

Q 行出力せよ。i 行目には i 番目のクエリの答えを出力せよ。


入力例 1

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

出力例 1

Yes
No
No
Yes
  • 1 番目のクエリについて、(1,2,3) を並び替えることで (2,3,1) に一致させることができます。よって Yes を出力します。
  • 2 番目のクエリについて、(1,2) をどのように並び替えても (1,4,2) に一致させることができません。よって No を出力します。
  • 3 番目のクエリについて、(1,2,3,2) をどのように並び替えても (3,1,4,2) に一致させることができません。よって No を出力します。
  • 4 番目のクエリについて、(1,2,3,2,4) を並び替えることで (2,3,1,4,2) に一致させることができます。よって Yes を出力します。

入力例 2

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

出力例 2

Yes
Yes
No
No

Score : 500 points

Problem Statement

You are given sequences of positive integers of length N: A=(A_1,A_2,\ldots,A_N) and B=(B_1,B_2,\ldots,B_N).

You are given Q queries to process in order. The i-th query is explained below.

  • You are given positive integers l_i,r_i,L_i,R_i. Print Yes if it is possible to rearrange the subsequence (A_{l_i},A_{l_i+1},\ldots,A_{r_i}) to match the subsequence (B_{L_i},B_{L_i+1},\ldots,B_{R_i}), and No otherwise.

Constraints

  • 1\leq N,Q\leq 2\times 10^5
  • 1\leq A_i,B_i\leq N
  • 1\leq l_i \leq r_i\leq N
  • 1\leq L_i \leq R_i\leq N
  • All input values are integers.

Input

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

N Q
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
l_1 r_1 L_1 R_1
l_2 r_2 L_2 R_2
\vdots
l_Q r_Q L_Q R_Q

Output

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


Sample Input 1

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

Sample Output 1

Yes
No
No
Yes
  • For the 1st query, it is possible to rearrange (1,2,3) to match (2,3,1). Hence, we print Yes.
  • For the 2nd query, it is impossible to rearrange (1,2) in any way to match (1,4,2). Hence, we print No.
  • For the 3rd query, it is impossible to rearrange (1,2,3,2) in any way to match (3,1,4,2). Hence, we print No.
  • For the 4th query, it is possible to rearrange (1,2,3,2,4) to match (2,3,1,4,2). Hence, we print Yes.

Sample Input 2

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

Sample Output 2

Yes
Yes
No
No