#include <bits/stdc++.h>
using namespace std;
int n, m;
int x[100005], c[100005];
long long sum_x[100005][2], sum_c[100005][2], sum_xc[100005][2], total[100005][2];
long long ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &x[i]);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", &c[i]);
}
for (int i = 1; i <= n; ++i) {
total[c[i]][i % 2] += 1;
sum_x[c[i]][i % 2] += x[i];
sum_x[c[i]][i % 2] %= 10007;
sum_c[c[i]][i % 2] += i;
sum_c[c[i]][i % 2] %= 10007;
sum_xc[c[i]][i % 2] += x[i] * i;
sum_xc[c[i]][i % 2] %= 10007;
}
for (int i = 1; i <= m; ++i) {
for (int j = 0; j <= 1; ++j) {
if (total[i][j] <= 1) {
continue ;
}
ans += sum_x[i][j] * sum_c[i][j] + (total[i][j] - 2) * sum_xc[i][j];
ans %= 10007;
if (ans < 0) ans = (ans + 10007) % 10007;
}
}
cout << ans << endl;
return 0;
}