#C8622. Subsequence Checker

    ID: 52625 Type: Default 1000ms 256MiB

Subsequence Checker

Subsequence Checker

You are given two arrays of integers, \(A\) and \(B\). Your task is to determine whether \(B\) is a subsequence of \(A\). A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

Definition: \(B\) is a subsequence of \(A\) if there exists a sequence of indices \(i_1, i_2, \ldots, i_m\) in \(A\) such that \(A[i_1] = B[0],\ A[i_2] = B[1], \ldots, A[i_m] = B[m-1]\) with \(i_1 < i_2 < \ldots < i_m\).

Print YES if \(B\) is a subsequence of \(A\), otherwise print NO.

inputFormat

The input is given from stdin in the following format:

  1. An integer \(n\) representing the number of elements in array \(A\).
  2. \(n\) space-separated integers representing array \(A\).
  3. An integer \(m\) representing the number of elements in array \(B\).
  4. If \(m > 0\), then \(m\) space-separated integers representing array \(B\). If \(m = 0\), this line will be empty.

outputFormat

Output a single line to stdout containing YES if \(B\) is a subsequence of \(A\), or NO otherwise.

## sample
5
1 2 3 4 5
3
1 3 5
YES