import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
class Node implements Comparable<Node>{
int index;
int num;
int color;
public Node(int i, int v, int c){
this.index = i; this.num = v;this.color = c;
}
public int compareTo(Node o){
if(this.color < o.color){
return -1;
}else if(this.color > o.color){
return 1;
}else{
if(this.index < o.index){
return -1;
}else{return 1;}
}
}
}
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] nm = bf.readLine().trim().split(" ");
int n = Integer.parseInt(nm[0]), m = Integer.parseInt(nm[1]);
String[] numStrs = bf.readLine().trim().split(" ");
String[] colorStrs = bf.readLine().trim().split(" ");
Node[] nodes = new Node[n];
for(int i = 0; i < n; ++i){
nodes[i] = new Node(i + 1, Integer.parseInt(numStrs[i]), Integer.parseInt(colorStrs[i]));
}
Arrays.sort(nodes);
/*for(Node node: nodes){
System.out.println(node.color + " " + node.index + " " + node.num);
}*/
int MOD = 10007;
long res = 0L;
int l = 0, r;
for(; l < n; ++l){
Node nodel = nodes[l];
for(r = l + 1; r < n; ++r){
Node noder = nodes[r];
if(noder.color == nodel.color){
if(((noder.index - nodel.index) & 1) == 0){
res = (res + ((long)noder.index + nodel.index) * (noder.num + nodel.num)) % MOD;
}
}else{
break;
}
}
}
System.out.println(res);
}
}