#K77557. Subsequence Checker

    ID: 34890 Type: Default 1000ms 256MiB

Subsequence Checker

Subsequence Checker

Given two sequences of positive integers, determine whether the first sequence is a subsequence of the second. A sequence A of length (n) is said to be a subsequence of sequence B of length (m) if there exist indices (1 \leq i_1 < i_2 < \cdots < i_n \leq m) such that (A[k] = B[i_k]) for each (1 \leq k \leq n).

You are given two sequences: the first sequence with length n and the second sequence with length m. Your task is to determine if the first sequence is a subsequence of the second. Output YES if it is, otherwise output NO.

inputFormat

The input is given via standard input and consists of four lines:

1. The first line contains an integer (n), the length of the first sequence.
2. The second line contains (n) space-separated integers representing the first sequence.
3. The third line contains an integer (m), the length of the second sequence.
4. The fourth line contains (m) space-separated integers representing the second sequence.

outputFormat

Output a single line YES if the first sequence is a subsequence of the second; otherwise, output NO.## sample

3
1 3 5
5
1 2 3 4 5
YES