#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x <<": " << x << endl;
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, 1, -1};
const int dz[] = {1, -1, 0, 0, 0, 0 };
int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct node {
ll x,y;
}q[maxn];
bool cmp(node a,node b){
return a.x<b.x;
}
ll dp[maxn];
ll n;
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>q[i].x;
for(int i=1;i<=n;i++)cin>>q[i].y;
sort(q+1,q+1+n,cmp);
ll ans=0;
dp[0]=1;
for(int i=1;i<=n;i++){
for(int j=q[i].y;j<=q[i].x;j++){
ans=(ans+dp[j-q[i].y])%MOD;
}
for(int j=5000;j>=q[i].y;j--){
dp[j]=(dp[j]+dp[j-q[i].y])%MOD;
}
}
cout<<ans<<endl;
}
int main()
{
//init();
ll t = 1;
//scanf("%lld",&t);
while(t--)
{
solve();
}
return 0;
}