1 #include <cstdio>
2 #include <cctype>
3 #include <algorithm>
4 #include <cstring>
5 #include <queue>
6 #include <cmath>
7
8 #if defined DEBUG
9 FILE *in = fopen("temp", "r");
10 #define out stdout
11 #else
12 FILE *in = fopen("MatchNOIP2013.in", "r");
13 FILE *out = fopen("MatchNOIP2013.out", "w");
14 #endif
15
16 inline void getint(int &x){
17 char c = fgetc(in);
18 while(!isdigit(c))c = fgetc(in);
19 x = c - ‘0‘;
20 while(isdigit(c = fgetc(in)))x = x * 10 - ‘0‘ + c;
21 }
22 typedef long long LL;
23 using namespace std;
24 inline int lowbit(int x){return x & -x;}
25 /*=====================================*/
26 const int maxn = 100000 + 5, mod = 99999997;
27 int n, A[maxn], B[maxn], t1[maxn], t2[maxn], ans = 0;
28
29 inline bool tmpa(int a, int b){return A[a] < A[b];}
30 inline bool tmpb(int a, int b){return B[a] < B[b];}
31
32 //namespace Fenwick{
33 int Arr[maxn] = {0};
34 inline void insert(int x){
35 ++Arr[x];
36 int i = x + lowbit(x);
37 while(i <= n){
38 ++Arr[i];
39 i += lowbit(i);
40 }
41 }
42 inline int getS(int x){
43 int ans = Arr[x], i = x ^ lowbit(x);
44 while(i){
45 ans += Arr[i];
46 i ^= lowbit(i);
47 }
48 return ans;
49 }
50 //}//Fenwick
51 //using Fenwick::getS;
52 //using Fenwick::insert;
53
54 inline void work(){
55 getint(n);
56 int i, ord[maxn];
57 for(i = 1;i <= n;++i)
58 getint(A[i]), t1[i] = i;
59 for(i = 1;i <= n;++i)
60 getint(B[i]), t2[i] = i;
61 sort(t1 + 1, t1 + n + 1, tmpa);
62 sort(t2 + 1, t2 + n + 1, tmpb);
63 for(i = 1;i <= n;++i)
64 ord[t1[i]] = t2[i];
65 for(i = n;i;--i){
66 ans = (ans + getS(ord[i])) % mod;
67 insert(ord[i]);
68 }
69 fprintf(out, "%d\n", (ans + mod) % mod);
70 }
71
72 int main(){
73
74 work();
75
76 return 0;
77 }