#include <bits/stdc++.h>
#define MAX_N 100005
using namespace std;
int n, m;
int a[MAX_N], b[MAX_N];
vector<int>p[MAX_N][2];
long long ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
cin >> b[i];
p[b[i]][i % 2].push_back(i);
}
for (int i = 1; i <= m; i++) {
int l = p[i][0].size();
for (int j = 0; j < l; j++)
for (int k = j + 1; k < l; k++)
ans = (ans + ((p[i][0][j] + p[i][0][k]) * (a[p[i][0][j]] + a[p[i][0][k]])) % 10007) % 10007;
l = p[i][1].size();
for (int j = 0; j < l; j++)
for (int k = j + 1; k < l; k++)
ans = (ans + ((p[i][1][j] + p[i][1][k]) * (a[p[i][1][j]] + a[p[i][1][k]])) % 10007) % 10007;
}
cout << ans % 10007;
return 0;
}