Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は、あるシステムのセキュリティ管理者です。このシステムでは、0 以上 10^9 以下の整数を要素とする長さ M の整数列がパスワードとして設定されています。
ある日、N 人のユーザーがそれぞれパスワードをメモした紙を提出しました。しかし、どのメモにもちょうど1箇所だけインクが滲んで読めなくなっている値があり、その箇所は -1 で表されています。それ以外の箇所はすべて正しく記録されています。
i 番目のユーザーのメモに書かれた整数列を S_{i,1}, S_{i,2}, \ldots, S_{i,M} とします。
高橋君は、すべてのメモが 同一のパスワード を記録したものであり得るかどうかを確認したいと考えています。すなわち、各メモの -1 の箇所を 0 以上 10^9 以下の適切な整数値で補うことで、すべてのメモが完全に一致するようにできるかを判定してください。
より正確には、以下の条件をすべて満たす、0 以上 10^9 以下の整数からなる長さ M の整数列 P = (P_1, P_2, \ldots, P_M) が存在するかどうかを判定してください。
- 各メモ i(1 \leq i \leq N)について、S_{i,j} \neq -1 であるすべての位置 j(1 \leq j \leq M)において、S_{i,j} = P_j が成り立つ。
(S_{i,j} = -1 である位置については、P_j の値に関する制約はありません。)
条件を満たす P が存在するならば Yes を、存在しないならば No を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- N \times M \leq 2 \times 10^5
- 各メモにはちょうど1箇所だけ -1 が含まれる。
- S_{i,j} = -1 または 0 \leq S_{i,j} \leq 10^9(1 \leq i \leq N, 1 \leq j \leq M)
- 入力はすべて整数である。
入力
N M
S_{1,1} S_{1,2} \cdots S_{1,M}
S_{2,1} S_{2,2} \cdots S_{2,M}
\vdots
S_{N,1} S_{N,2} \cdots S_{N,M}
- 1 行目には、メモの枚数 N と、パスワードの長さ M が、スペース区切りで与えられる。
- 続く N 行のうち i 行目(1 \leq i \leq N)には、i 番目のメモの整数列 S_{i,1}, S_{i,2}, \ldots, S_{i,M} がスペース区切りで与えられる。各メモにはちょうど1箇所だけ -1 が含まれ、それ以外の値は 0 以上 10^9 以下の整数である。
出力
条件を満たす整数列 P が存在するならば Yes を、存在しないならば No を1行で出力せよ。
入力例 1
3 4 -1 2 3 4 1 -1 3 4 1 2 -1 4
出力例 1
Yes
入力例 2
3 4 -1 2 3 4 1 -1 3 4 1 5 -1 4
出力例 2
No
入力例 3
5 6 -1 20 30 40 50 60 10 -1 30 40 50 60 10 20 -1 40 50 60 10 20 30 -1 50 60 10 20 30 40 -1 60
出力例 3
Yes
入力例 4
10 10 -1 2 3 4 5 6 7 8 9 10 1 -1 3 4 5 6 7 8 9 10 1 2 -1 4 5 6 7 8 9 10 1 2 3 -1 5 6 7 8 9 10 1 2 3 4 -1 6 7 8 9 10 1 2 3 4 5 -1 7 8 9 10 1 2 3 4 5 6 -1 8 9 10 1 2 3 4 5 6 7 -1 9 10 1 2 3 4 5 6 7 8 -1 10 1 2 3 4 5 6 7 8 9 -1
出力例 4
Yes
入力例 5
1 1 -1
出力例 5
Yes
Score : 266 pts
Problem Statement
Takahashi is the security administrator of a certain system. In this system, a password is set as an integer sequence of length M whose elements are integers between 0 and 10^9, inclusive.
One day, N users each submitted a piece of paper on which they had written down the password. However, on every memo, exactly one value has become unreadable due to ink smudging, and that position is represented by -1. All other positions are recorded correctly.
Let S_{i,1}, S_{i,2}, \ldots, S_{i,M} denote the integer sequence written on the i-th user's memo.
Takahashi wants to check whether it is possible that all memos recorded the same password. That is, determine whether it is possible to replace the -1 in each memo with an appropriate integer between 0 and 10^9, inclusive, so that all memos become completely identical.
More precisely, determine whether there exists an integer sequence P = (P_1, P_2, \ldots, P_M) of length M, consisting of integers between 0 and 10^9 inclusive, that satisfies all of the following conditions:
- For each memo i (1 \leq i \leq N), for every position j (1 \leq j \leq M) where S_{i,j} \neq -1, it holds that S_{i,j} = P_j.
(For positions where S_{i,j} = -1, there are no constraints on the value of P_j.)
If such a P exists, print Yes; otherwise, print No.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- N \times M \leq 2 \times 10^5
- Each memo contains exactly one -1.
- S_{i,j} = -1 or 0 \leq S_{i,j} \leq 10^9 (1 \leq i \leq N, 1 \leq j \leq M)
- All input values are integers.
Input
N M
S_{1,1} S_{1,2} \cdots S_{1,M}
S_{2,1} S_{2,2} \cdots S_{2,M}
\vdots
S_{N,1} S_{N,2} \cdots S_{N,M}
- The first line contains the number of memos N and the password length M, separated by a space.
- The following N lines each describe a memo. The i-th line (1 \leq i \leq N) contains the integer sequence S_{i,1}, S_{i,2}, \ldots, S_{i,M} separated by spaces. Each memo contains exactly one -1, and all other values are integers between 0 and 10^9, inclusive.
Output
Print Yes on a single line if an integer sequence P satisfying the conditions exists; otherwise, print No.
Sample Input 1
3 4 -1 2 3 4 1 -1 3 4 1 2 -1 4
Sample Output 1
Yes
Sample Input 2
3 4 -1 2 3 4 1 -1 3 4 1 5 -1 4
Sample Output 2
No
Sample Input 3
5 6 -1 20 30 40 50 60 10 -1 30 40 50 60 10 20 -1 40 50 60 10 20 30 -1 50 60 10 20 30 40 -1 60
Sample Output 3
Yes
Sample Input 4
10 10 -1 2 3 4 5 6 7 8 9 10 1 -1 3 4 5 6 7 8 9 10 1 2 -1 4 5 6 7 8 9 10 1 2 3 -1 5 6 7 8 9 10 1 2 3 4 -1 6 7 8 9 10 1 2 3 4 5 -1 7 8 9 10 1 2 3 4 5 6 -1 8 9 10 1 2 3 4 5 6 7 -1 9 10 1 2 3 4 5 6 7 8 -1 10 1 2 3 4 5 6 7 8 9 -1
Sample Output 4
Yes
Sample Input 5
1 1 -1
Sample Output 5
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は洗濯物を片付けています。洗濯かごの中には N 枚の靴下があり、i 番目の靴下 (1 \leq i \leq N) には色の濃さを表す整数値 A_i が設定されています。異なる靴下が同じ色の濃さを持つこともあります。
高橋君はこれらの靴下からペアを作りたいと考えています。高橋君は几帳面な性格なので、2枚の靴下をペアにするには、それらの色の濃さの差の絶対値が K 以下である必要があります。すなわち、i 番目の靴下と j 番目の靴下 (i \neq j) をペアにできるのは、|A_i - A_j| \leq K を満たすときに限ります。
1つのペアはちょうど2枚の靴下からなり、各靴下はたかだか1つのペアにしか使用できません。ペアに使われない靴下が残っても構いません。
高橋君が作ることができる靴下のペアの最大個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、靴下の枚数を表す整数 N と、ペアとして認める色の濃さの差の上限を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各靴下の色の濃さを表す N 個の整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
高橋君が作ることができる靴下のペアの最大個数を 1 行で出力せよ。
入力例 1
6 2 1 3 5 2 8 7
出力例 1
3
入力例 2
10 3 1 5 9 13 17 2 6 10 14 18
出力例 2
5
入力例 3
15 100 50 200 350 500 120 80 210 340 510 130 75 220 360 490 140
出力例 3
6
Score : 300 pts
Problem Statement
Takahashi is putting away the laundry. There are N socks in the laundry basket, and the i-th sock (1 \leq i \leq N) has an integer value A_i representing its color intensity. Different socks may have the same color intensity.
Takahashi wants to make pairs from these socks. Being a meticulous person, he requires that the absolute difference in color intensity between two socks in a pair is at most K. That is, the i-th sock and the j-th sock (i \neq j) can be paired only if |A_i - A_j| \leq K.
Each pair consists of exactly 2 socks, and each sock can be used in at most one pair. It is fine if some socks are left unpaired.
Find the maximum number of pairs of socks that Takahashi can make.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
N K A_1 A_2 \ldots A_N
- The first line contains two integers separated by a space: N, the number of socks, and K, the maximum allowable difference in color intensity for a pair.
- The second line contains N integers A_1, A_2, \ldots, A_N separated by spaces, representing the color intensity of each sock.
Output
Print the maximum number of pairs of socks that Takahashi can make, in a single line.
Sample Input 1
6 2 1 3 5 2 8 7
Sample Output 1
3
Sample Input 2
10 3 1 5 9 13 17 2 6 10 14 18
Sample Output 2
5
Sample Input 3
15 100 50 200 350 500 120 80 210 340 510 130 75 220 360 490 140
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は N 文字からなるリボンを持っており、左から順に英大文字からなる文字列 S が書かれています。
高橋君はこのリボンを、隣り合う文字と文字の間の相異なる位置で、合計 M 回以下切ることができます。
k 回切断すると、リボンは k + 1 個の空でない連続した断片に分かれます。各文字はちょうど 1 つの断片に含まれ、断片の順序は元の文字列 S における順序を保ちます。切断を 1 回も行わない場合、リボン全体が 1 つの断片となります。
断片に書かれた文字列がちょうど ATCODER であるとき、その断片を 当たり断片 と呼びます。
高橋君は、当たり断片の個数をできるだけ多くしたいです。
M 回以下の切断で得られる当たり断片の個数の最大値を求めてください。
制約
- 1 \leq N \leq 10^6
- 0 \leq M \leq N - 1
- S は英大文字からなる長さ N の文字列
- N, M は整数
入力
N M S
1 行目には、リボンの文字数 N と切断できる回数の上限 M が、スペース区切りで与えられる。
2 行目には、リボンに書かれた長さ N の文字列 S が与えられる。
出力
M 回以下の切断で得られる当たり断片の個数の最大値を、1 行で出力せよ。
入力例 1
7 0 ATCODER
出力例 1
1
入力例 2
14 1 ATCODERATCODER
出力例 2
2
入力例 3
54 8 HELLOATCODERWORLDATCODERATCODERXYZATCODERQQQATCODEREND
出力例 3
4
入力例 4
210 29 ATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODER
出力例 4
30
入力例 5
1 0 A
出力例 5
0
Score : 366 pts
Problem Statement
Takahashi has a ribbon consisting of N characters, with a string S of uppercase English letters written on it from left to right.
Takahashi can cut this ribbon at most M times at distinct positions between adjacent characters.
If he makes k cuts, the ribbon is divided into k + 1 non-empty contiguous pieces. Each character belongs to exactly one piece, and the order of the pieces preserves the order in the original string S. If no cuts are made, the entire ribbon remains as one piece.
A piece is called a winning piece if the string written on it is exactly ATCODER.
Takahashi wants to maximize the number of winning pieces.
Find the maximum number of winning pieces that can be obtained with at most M cuts.
Constraints
- 1 \leq N \leq 10^6
- 0 \leq M \leq N - 1
- S is a string of length N consisting of uppercase English letters
- N, M are integers
Input
N M S
The first line contains the number of characters on the ribbon N and the maximum number of cuts M, separated by a space.
The second line contains the string S of length N written on the ribbon.
Output
Print the maximum number of winning pieces that can be obtained with at most M cuts, on a single line.
Sample Input 1
7 0 ATCODER
Sample Output 1
1
Sample Input 2
14 1 ATCODERATCODER
Sample Output 2
2
Sample Input 3
54 8 HELLOATCODERWORLDATCODERATCODERXYZATCODERQQQATCODEREND
Sample Output 3
4
Sample Input 4
210 29 ATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODERATCODER
Sample Output 4
30
Sample Input 5
1 0 A
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は、病院の受付窓口の順番管理システムを担当しています。窓口には 1 つの待ち行列があり、患者は到着順に末尾へ並びます。
しかし、この病院では緊急患者用の優先カードが存在します。優先カードを持っている患者は、待ち行列の指定された位置に割り込むことができます。高橋君は、割り込みが発生するたびに待ち行列全体の状態を正しく把握しておく必要があります。
最初、待ち行列は空です。以下の Q 個の操作が順番に与えられます。
- 操作 1 :
1 x— 患者番号 x の患者が待ち行列の末尾に並ぶ。 - 操作 2 :
2 x k— 優先カードを持つ患者番号 x の患者が、待ち行列の先頭から k 番目の位置に挿入される。すなわち、この操作の直後において、待ち行列の先頭から k 番目が患者番号 x の患者となる。挿入前に先頭から k 番目以降にいた患者は、それぞれ 1 つずつ後ろにずれる。 - 操作 3 :
3— 待ち行列の先頭の患者が窓口で対応され、待ち行列から取り除かれる。
なお、異なる操作で同じ患者番号が与えられることがありますが、それらは別々の患者として扱われ、それぞれ独立に待ち行列に追加されます。
操作 3 が行われるたびに、取り除かれた患者の患者番号を出力してください。
制約
- 1 \leq Q \leq 2 \times 10^5
- 操作 1, 2 における患者番号 x は 1 \leq x \leq 10^9 を満たす整数である。
- 操作 2 における挿入位置 k は、1 \leq k \leq (\text{その操作の直前の待ち行列の長さ}) + 1 を満たす整数である。特に k がその操作の直前の待ち行列の長さに 1 を加えた値に等しい場合、患者は末尾に追加される。
- 操作 3 が行われるとき、待ち行列は空でないことが保証される。
- 入力で与えられる値はすべて整数である。
入力
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
1 行目には、操作の個数を表す整数 Q が与えられる。
2 行目から Q 行にわたって、各操作が 1 行ずつ与えられる。各行の先頭の整数が操作の種類を表す。
- 操作 1 の場合:
1 xの形式で、末尾に並ぶ患者の患者番号 x が与えられる。 - 操作 2 の場合:
2 x kの形式で、割り込む患者の患者番号 x と、挿入先の位置 k が与えられる。 - 操作 3 の場合:
3のみが与えられる。
出力
操作 3 が行われるたびに、待ち行列の先頭から取り除かれた患者の患者番号を 1 行に 1 つずつ出力せよ。
入力例 1
7 1 10 1 20 2 30 2 3 2 40 1 3 3
出力例 1
10 40 30
入力例 2
6 2 5 1 1 5 2 7 3 3 3 3
出力例 2
5 5 7
入力例 3
18 1 100 1 200 2 300 1 1 400 2 500 3 3 2 600 5 3 1 700 2 800 2 3 3 2 900 1 1 1000 2 1100 4 3 3 3
出力例 3
300 100 500 800 900 200 400
入力例 4
40 1 1000000000 1 1 1 2 2 999999999 1 2 123456789 3 3 1 3 2 4 6 2 5 2 3 3 1 6 2 7 1 2 8 4 1 9 3 2 10 9 1 11 2 12 5 3 3 2 13 1 2 14 10 1 15 3 1 16 2 17 7 2 18 14 3 3 3 2 19 1 1 20 2 21 13 3 1 22 2 23 15 3 3 3
出力例 4
999999999 1000000000 5 7 123456789 1 13 8 2 12 19 3 4 6
入力例 5
2 2 1000000000 1 3
出力例 5
1000000000
Score : 400 pts
Problem Statement
Takahashi is in charge of the queue management system for a hospital's reception counter. The counter has a single queue, and patients line up at the end in order of arrival.
However, this hospital has priority cards for emergency patients. A patient holding a priority card can cut into the queue at a specified position. Takahashi needs to correctly keep track of the entire state of the queue every time a cut-in occurs.
Initially, the queue is empty. The following Q operations are given in order.
- Operation 1:
1 x— Patient with patient number x lines up at the end of the queue. - Operation 2:
2 x k— A patient with patient number x holding a priority card is inserted at the k-th position from the front of the queue. That is, immediately after this operation, the k-th person from the front of the queue is the patient with patient number x. Patients who were at position k or later from the front before the insertion are each shifted one position back. - Operation 3:
3— The patient at the front of the queue is served at the counter and removed from the queue.
Note that the same patient number may appear in different operations, but they are treated as separate patients and are each independently added to the queue.
Each time operation 3 is performed, output the patient number of the removed patient.
Constraints
- 1 \leq Q \leq 2 \times 10^5
- The patient number x in operations 1 and 2 is an integer satisfying 1 \leq x \leq 10^9.
- The insertion position k in operation 2 is an integer satisfying 1 \leq k \leq (\text{length of the queue immediately before that operation}) + 1. In particular, if k equals the length of the queue immediately before the operation plus 1, the patient is added to the end.
- When operation 3 is performed, it is guaranteed that the queue is not empty.
- All values given in the input are integers.
Input
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
The first line contains an integer Q representing the number of operations.
From the second line onward, each operation is given on a single line over Q lines. The first integer on each line indicates the type of operation.
- For operation 1: Given in the format
1 x, where x is the patient number of the patient lining up at the end. - For operation 2: Given in the format
2 x k, where x is the patient number of the patient cutting in and k is the insertion position. - For operation 3: Only
3is given.
Output
Each time operation 3 is performed, output the patient number of the patient removed from the front of the queue, one per line.
Sample Input 1
7 1 10 1 20 2 30 2 3 2 40 1 3 3
Sample Output 1
10 40 30
Sample Input 2
6 2 5 1 1 5 2 7 3 3 3 3
Sample Output 2
5 5 7
Sample Input 3
18 1 100 1 200 2 300 1 1 400 2 500 3 3 2 600 5 3 1 700 2 800 2 3 3 2 900 1 1 1000 2 1100 4 3 3 3
Sample Output 3
300 100 500 800 900 200 400
Sample Input 4
40 1 1000000000 1 1 1 2 2 999999999 1 2 123456789 3 3 1 3 2 4 6 2 5 2 3 3 1 6 2 7 1 2 8 4 1 9 3 2 10 9 1 11 2 12 5 3 3 2 13 1 2 14 10 1 15 3 1 16 2 17 7 2 18 14 3 3 3 2 19 1 1 20 2 21 13 3 1 22 2 23 15 3 3 3
Sample Output 4
999999999 1000000000 5 7 123456789 1 13 8 2 12 19 3 4 6
Sample Input 5
2 2 1000000000 1 3
Sample Output 5
1000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
N 枚のカードが横一列に並んでいます。左から i 番目のカードには英小文字 S_i が印字されており、色 P_i で塗られています。ここで A, B, C は互いに異なる 3 色を表し、P_i はそのいずれかです。カードに印字された文字と色は変更できません。
高橋君は、はじめに N 枚すべてのカードに対して、各カードにちょうど 1 つずつ、1 以上 M 以下の整数を書き込みます。異なるカードに同じ整数を書き込んでもかまいません。
整数の書き込みが完了した後、高橋君は次の操作を好きな回数(0 回でもよい)繰り返し行い、好きなタイミングで終了できます。
- 現在残っているカード列の中から、隣り合う 2 枚のカードであって、色が同じかつ書き込まれた整数も同じであるものを 1 組選び、その 2 枚を取り除く。印字された文字は一致していなくてもよい。取り除いた後、残ったカードは隙間を詰めて一列に並べ直す(相対的な順序は保たれる)。
長さ L の英小文字からなる文字列 T と、長さ L の整数列 Q が与えられます。
整数の書き込み方と操作の手順を適切に選ぶことで、操作終了時に残っているカードがちょうど L 枚であり、かつそれらを左から順に見たとき、印字された文字の列が T に一致し、書き込まれた整数の列が Q に一致するようにできるか判定してください。
制約
- 1 \leq L \leq N \leq 1000
- 1 \leq M \leq N
- S は長さ N の英小文字からなる文字列
- P は長さ N の文字列であり、各文字は
A,B,Cのいずれか - T は長さ L の英小文字からなる文字列
- 1 \leq Q_i \leq M (1 \leq i \leq L)
- 入力はすべて整数または文字列である
入力
N M L S P T Q_1 Q_2 \cdots Q_L
1 行目にはカードの枚数 N、書き込める整数の上限 M、目標の列の長さ L がスペース区切りで与えられます。2 行目には各カードに印字された文字を並べた文字列 S が、3 行目には各カードの色を並べた文字列 P が与えられます。4 行目には目標の文字列 T が、5 行目には目標の整数列 Q_1, Q_2, \ldots, Q_L がスペース区切りで与えられます。
出力
条件を満たせるなら Yes を、そうでないなら No を出力せよ。
入力例 1
4 3 2 abcd AABC cd 2 3
出力例 1
Yes
入力例 2
4 2 1 abca AABB a 1
出力例 2
No
入力例 3
12 3 4 abcdefghijkl AACBBACCBAAC cfil 1 2 1 3
出力例 3
Yes
入力例 4
30 30 10 abcdefghijklmnopqrstuvwxyzabcd AABBCCAABBCCAABBCCAAABCABCABCA uvwxyzabcd 30 1 30 2 29 3 28 4 27 5
出力例 4
Yes
入力例 5
1 1 1 z C z 1
出力例 5
Yes
Score : 466 pts
Problem Statement
There are N cards arranged in a row from left to right. The i-th card from the left has a lowercase English letter S_i printed on it and is painted with a color P_i. Here, A, B, and C represent 3 distinct colors, and P_i is one of them. The letters and colors printed on the cards cannot be changed.
First, Takahashi writes an integer between 1 and M, inclusive, on each of the N cards. He may write the same integer on different cards.
After writing the integers, Takahashi can repeat the following operation any number of times (possibly zero) and end the process at any time:
- Choose 1 pair of adjacent cards from the currently remaining cards that have the same color and the same written integer, and remove those 2 cards. The printed letters do not need to match. After removing them, close the gaps and rearrange the remaining cards into a single row (their relative order is preserved).
You are given a string T of length L consisting of lowercase English letters, and a sequence of integers Q of length L.
Determine whether it is possible to choose how to write the integers and the sequence of operations such that, when the operations end, exactly L cards remain, and when viewed from left to right, the sequence of printed letters matches T and the sequence of written integers matches Q.
Constraints
- 1 \leq L \leq N \leq 1000
- 1 \leq M \leq N
- S is a string of length N consisting of lowercase English letters.
- P is a string of length N where each character is
A,B, orC. - T is a string of length L consisting of lowercase English letters.
- 1 \leq Q_i \leq M (1 \leq i \leq L)
- All inputs are integers or strings.
Input
N M L S P T Q_1 Q_2 \cdots Q_L
The first line contains the number of cards N, the upper bound M for the integers that can be written, and the target length L, separated by spaces. The second line contains a string S representing the letters printed on the cards. The third line contains a string P representing the colors of the cards. The fourth line contains the target string T. The fifth line contains the target integer sequence Q_1, Q_2, \ldots, Q_L, separated by spaces.
Output
If the condition can be satisfied, print Yes; otherwise, print No.
Sample Input 1
4 3 2 abcd AABC cd 2 3
Sample Output 1
Yes
Sample Input 2
4 2 1 abca AABB a 1
Sample Output 2
No
Sample Input 3
12 3 4 abcdefghijkl AACBBACCBAAC cfil 1 2 1 3
Sample Output 3
Yes
Sample Input 4
30 30 10 abcdefghijklmnopqrstuvwxyzabcd AABBCCAABBCCAABBCCAAABCABCABCA uvwxyzabcd 30 1 30 2 29 3 28 4 27 5
Sample Output 4
Yes
Sample Input 5
1 1 1 z C z 1
Sample Output 5
Yes