#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <queue>
#define pa system("pause");
#define fc fclose(stdin);fclose(stdout);return 0;
using namespace std;
const int mod = 10007 ;
const int maxn = 200000 + 10 ;
int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,x,z;
long long ans;
int color[maxn],num[maxn];
int tot[maxn][2],cnt[maxn][2],sum[maxn][2],add[maxn][2];
/*
x*num[x] + x*num[y] + y * num[x] + y * num[y];
x*num[x] + x*num[z] + z * num[x] + z * num[z] ;
*/
void work(int x){
int op = x % 2 ; //奇数为1 偶数为0
ans += 1ll*x*num[x]*cnt[color[x]][op]%mod;
ans %= mod ;
ans += 1ll*x*sum[color[x]][op]%mod;
ans %= mod ;
ans += 1ll*tot[color[x]][op]*num[x]%mod;
ans %= mod ;
ans += 1ll*add[color[x]][op]%mod;
ans %= mod ;
cnt[color[x]][op]++;
cnt[color[x]][op]%=mod;
sum[color[x]][op]+=num[x];
sum[color[x]][op]%=mod;
tot[color[x]][op]+=x;
tot[color[x]][op]%=mod;
add[color[x]][op]+=1ll*x*num[x]%mod;
add[color[x]][op]%=mod;
}
int main(){
freopen("2015sum.in","r",stdin);
freopen("2015sum.out","w",stdout);
n=read();m=read();
for(int i=1;i<=n;i++)num[i]=read(),num[i]%=mod;
for(int i=1;i<=n;i++){
color[i]=read();
work(i);
}
printf("%lld\n",(ans+mod)%mod);
fc;
}