We are given a problem: Chef has a sequence of N numbers. He likes a sequence better if it contains his favorite sequence as a substring.
We are given T test cases. For each test case, the input consists of:
- First line: N (length of sequence)
- Second line: sequence of N integers (space separated)
- Third line: M (length of favorite sequence)
- Fourth line: sequence of M integers (favorite sequence)
We need to print "Yes" if the main sequence contains the favorite sequence as a contiguous substring; otherwise "No".
Constraints: T up to 10, N and M? Not specified precisely but likely 1 <= something. We can assume typical constraints.
The sample input:
2
6
1 2 3 4 5 6
3
2 3 4
6
22 5 6 33 1 4
2
4 15
Output:
Yes
No
So we need to implement substring matching.
Edge cases: M > N then impossible, answer No.
Otherwise, we need to check if there exists i such that sequence[i...i+M-1] equals favorite sequence.
Simplest: for each start index from 0 to N-M, compare sublist.
Given that constraints are small, this is fine.
But the problem statement has some formatting issues: "1<=T<=10
1
1" seems to be cut off. Probably they meant 1<=N, M <= something. We'll just read integers.
Implementation:
Read integer T.
Loop for each test case:
- Read N (may be on its own line; note that after T, there may be blank lines? We'll just use input().strip() but careful for empty lines). Better to read using sys.stdin and ignore empty lines.
Simplest: use input() in a loop that skips empty lines if needed. But typical judge input won't have extra blank lines.
We'll read:
N = int(input().strip())
seq = list(map(int, input().split()))
M = int(input().strip())
fav = list(map(int, input().split()))
Then check.
However, note that the input lines may have leading/trailing spaces, but split handles.
Check:
if M > N: print("No")
else:
found = any(seq[i:i+M] == fav for i in range(N - M + 1))
print("Yes" if found else "No")
That's it.
But we need to be careful: The sample input is:
2
6
1 2 3 4 5 6
3
2 3 4
6
22 5 6 33 1 4
2
4 15
All numbers are separated by spaces, and lines as described.
So implementation straightforward.
But maybe there are multiple test cases and we need to output each on new line.
We'll produce code accordingly.
Now, produce final answer: Explanation and code.
The problem is simple, but I'll include explanation.
I will produce a Python solution. Use sys.stdin to read all at once to avoid issues? But simple.
Now as the assistant: We need to output final answer with solution in Python.
Let's write:
def solve():
import sys
data = sys.stdin.read().strip().split()
# Parse: first token T
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
N = int(next(it))
seq = [int(next(it)) for _ in range(N)]
M = int(next(it))
fav = [int(next(it)) for _ in range(M)]
if M > N:
out_lines.append("No")
continue
found = False
for i in range(N - M + 1):
if seq[i:i+M] == fav:
found = True
break
out_lines.append("Yes" if found else "No")
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()
This handles any whitespace nicely.
Alternatively simpler: using input() in loop. But above is safer.
Now produce final. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
T = int(next(it))
results = []
for _ in range(T):
N = int(next(it))
seq = [int(next(it)) for _ in range(N)]
M = int(next(it))
fav = [int(next(it)) for _ in range(M)]
if M > N:
results.append("No")
continue
found = False
for i in range(N - M + 1):
if seq[i:i + M] == fav:
found = True
break
results.append("Yes" if found else "No")
sys.stdout.write("\n".join(results))
if name == "main":
solve()