a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
m=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
g={}
s=k=0
l=998244353
for i in range(m):
g[x[i]]=y[i]
for i in range(a):
if b[i] not in g or g[b[i]]<c[i]:
s+=1
if b[i] in g and g[b[i]]<=c[i]:
k+=1
if k==m:
print((2**s)%l)
else:
print(0)
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <iostream>
#include <iomanip>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <fstream>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (long long i = 0; i < n; i++)
#define whole(a) a.begin(), a.end()
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
long long mod = 998244353;
long long mult(long long a, long long b)
{
return (((a % mod + mod) % mod) * ((b % mod + mod) % mod)) % mod;
}
long long sum(long long a, long long b)
{
return (a + b + 3 * mod) % mod;
}
long long binpow(long long x, long long n)
{
if (n == 0) return 1;
if (n & 1) return mult(x, binpow(x, n - 1)) % mod;
long long t = binpow(x, n / 2) % mod;
return mult(t, t);
}
long long divide(long long a, long long b)
{
return a * binpow(b, mod - 2) % mod;
}
void solve()
{
ll n;
cin >> n;
vector<ll> a1(n), a2(n);
forn(i, n)
cin >> a1[i];
forn(i, n)
cin >> a2[i];
ll m;
cin >> m;
vector<ll> b1(m), b2(m);
forn(i, m)
cin >> b1[i];
forn(i, m)
cin >> b2[i];
ll k = 0;
ll cnt = n;
forn(i, m)
{
while (k < n && a1[k] != b1[i]) k++;
if (k == n)
{
cout << 0;
return;
}
if (a2[k] == b2[i])
cnt--;
else if (a2[k] < b2[i])
{
cout << 0;
return;
}
}
cout << binpow(2, cnt) << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
long long t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
1584B - Coloring Rectangles | 1562B - Scenes From a Memory |
1521A - Nastia and Nearly Good Numbers | 208. Implement Trie |
1605B - Reverse Sort | 1607C - Minimum Extraction |
1604B - XOR Specia-LIS-t | 1606B - Update Files |
1598B - Groups | 1602B - Divine Array |
1594B - Special Numbers | 1614A - Divan and a Store |
2085. Count Common Words With One Occurrence | 2089. Find Target Indices After Sorting Array |
2090. K Radius Subarray Averages | 2091. Removing Minimum and Maximum From Array |
6. Zigzag Conversion | 1612B - Special Permutation |
1481. Least Number of Unique Integers after K Removals | 1035. Uncrossed Lines |
328. Odd Even Linked List | 1219. Path with Maximum Gold |
1268. Search Suggestions System | 841. Keys and Rooms |
152. Maximum Product Subarray | 337. House Robber III |
869. Reordered Power of 2 | 1593C - Save More Mice |
1217. Minimum Cost to Move Chips to The Same Position | 347. Top K Frequent Elements |