#include <iostream>
using namespace std;

int main() {
  int N, M;
  int A[200010], B[200010];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  cin >> M;
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
  }

  int ans = 0;
  int cur = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] == B[cur]) {
      ++cur;
      if (cur == M) {
        ans = 1;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

