#include <fstream>
using namespace std;
ifstream in("pedefe.in");
ofstream out("pedefe.out");
const int nmax = 500, szmax = 100, mod = 666013;
int n, m, sz, a[nmax + 2], b[nmax + 2], subseq[szmax + 2];
int dp[szmax + 2][nmax + 2][nmax + 2];
int addmod(int xx, int yy){
xx += yy;
if(xx >= mod){
xx -= mod;
}
return xx;
}
int main(){
in>>n>>m>>sz;
for(int i = 1; i <= n; i++) in>>a[i];
for(int i = 1; i <= m; i++) in>>b[i];
for(int i = 1; i <= sz; i++) in>>subseq[i];
dp[0][0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i] != b[j]){ continue; }
for(int xx = 0; xx < i; xx++){
for(int yy = 0; yy < j; yy++){
if(a[xx] != b[yy] && a[xx] > a[i]){ continue; }
dp[0][i][j] = addmod(dp[0][i][j], dp[0][xx][yy]);
}
}
}
}
for(int it = 1; it <= sz; it++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i] != b[j]){ continue; } /// invalid state ///
for(int xx = 0; xx < i; xx++){
for(int yy = 0; yy < j; yy++){
if(a[xx] != b[yy] || a[xx] > a[i]){ continue; }
dp[it][i][j] = addmod(dp[it][i][j], dp[it][xx][yy]);
if(a[i] == subseq[it]){
dp[it][i][j] = addmod(dp[it][i][j], dp[it - 1][xx][yy]);
}
}
}
}
}
}
int all_ways = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
all_ways = addmod(all_ways, dp[sz][i][j]);
}
}
out<<all_ways<<"\n";
return 0;
}