//dp[i][j]表示前i个小朋友中左括号与右括号的差为j的最大实力值
//dp1[i][j]表示前i个小朋友中左括号与右括号的差为j的方案总数。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1e7 + 5;
const int mod = 998244353;
int n, w[maxn], c[maxn];
long long dp[5][maxn], dp1[5][maxn];
int s = 0;
void freopen() {
freopen("pick.in", "r", stdin);
freopen("pick.out", "w", stdout);
}
int MAX(int x, int y) {
return x > y ? x : y;
}
int main() {
freopen();
scanf("%d",&n);
for(int i = 1;i <= n;i ++) {
scanf("%d", &w[i]);
}
for(int i = 1;i <= n;i ++) {
scanf("%d", &c[i]);
}
dp[0][0] = 0, s = 0;
for(int i = 1;i <= n;i ++){
s = 1 - s;
for(int j = 0;j <= n;j ++){
if(!j) {
dp[s][j] = max(dp[1 - s][j] , dp[1 - s][j + 1]);
if(j >= c[i]) dp[s][j] = max(dp[s][j], dp[1 - s][j - c[i]] + w[i]);
}
else {
dp[s][j] = dp[1 - s][j + 1];
if(j >= c[i]) dp[s][j] = max(dp[s][j], dp[1 - s][j - c[i]] + w[i]);
}
}
}
printf("%lld ",dp[s][0]);
dp1[0][0] = 1, s = 0;
for(int i = 1;i <= n;i ++){
s = 1 - s;
for(int j = 0;j <= n;j ++){
if(!j){
dp1[s][j] = (dp1[1 - s][j] + dp1[1 - s][j + 1]) % mod;
if(j >= c[i]) dp1[s][j] = (dp1[s][j] + dp1[1 - s][j - c[i]]) % mod;
}else{
dp1[s][j] = dp1[1 - s][j + 1];
if(j >= c[i]) dp1[s][j] = (dp1[s][j] + dp1[1 - s][j - c[i]]) % mod;
}
}
}
printf("%lld", dp1[s][0]);
return 0;
}