#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int M = 3e5 + 10;
long long n, m, k, b[M], sum[N], a[N], p[M];
long long read() {
long long f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return f * x;
}
void write(long long x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)write(x / 10);
putchar(x % 10 + '0');
}
map<long long, long long>ma;
int main() {
long long tot = 1;
n = read();
m = read();
k = read();
for (int i = 1; i <= m; i++)b[i] = read();
sum[0] = -k + 1;
for (int i = 1; i <= n; i++) {
a[i] = read();
sum[i] = sum[i - 1] + a[i];
sum[i] %= k;
p[i] = p[i - 1];
if (i == b[tot]) {
if (sum[i] == 1)p[i]++;
tot++;
}
}
long long ans = p[n];
tot = m;
for (int i = n; i >= 1; i--) {
if (i == b[tot]) {
ma[sum[b[tot]]]++;
tot--;
}
a[i] %= k;
ans = max(ans, ma[a[i]] + p[i - 1]);
}
write(ans);
return 0;
}