#K69292. Subsequence Verification

    ID: 33054 Type: Default 1000ms 256MiB

Subsequence Verification

Subsequence Verification

Given two sequences of integers, determine whether the second sequence is a subsequence of the first one.

A sequence B is a subsequence of sequence A if B can be derived from A by deleting some (or no) elements without changing the order of the remaining elements. In simpler terms, all the elements of the recorded sequence should appear in the known pattern in the same order, although not necessarily consecutively.

Your task is to print Yes if the recorded sequence is a subsequence of the known pattern, and No otherwise.

Note that an empty recorded sequence is considered a valid subsequence of any sequence.

inputFormat

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

  1. The first line contains an integer n denoting the number of elements in the known pattern.
  2. The second line contains n space-separated integers representing the known pattern.
  3. The third line contains an integer m denoting the number of elements in the recorded sequence.
  4. The fourth line contains m space-separated integers representing the recorded sequence (this line can be empty if m is 0).

outputFormat

Output a single line to standard output (stdout) containing the string Yes if the recorded sequence is a subsequence of the known pattern; otherwise, output No.## sample

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