#include int main () { int n = 0; int k = 0; int c[1000] = {}; int d[1000] = {}; int res = 0; long long ans = 0LL; long long mod_num = 998244353LL; int d_max_cnt[1001][2] = {}; int d_max[1001] = {}; long long cnt[1001][501] = {}; long long comb[1001][1001] = {}; int max = -1; long long pow[1001][501] = {}; res = scanf("%d", &n); res = scanf("%d", &k); for (int i = 0; i < n; i++) { res = scanf("%d", c+i); } for (int i = 0; i < n; i++) { res = scanf("%d", d+i); } for (int i = 0; i <= k; i++) { comb[i][0] = 1LL; comb[i][i] = 1LL; for (int j = 1; j < i; j++) { comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%mod_num; } } for (int i = 0; i < n; i++) { if (d_max_cnt[c[i]][0] < d[i]) { d_max_cnt[c[i]][0] = d[i]; d_max_cnt[c[i]][1] = 1; } else if (d_max_cnt[c[i]][0] == d[i]) { d_max_cnt[c[i]][1]++; } } for (int i = 2; i <= k; i++) { if (d_max_cnt[i][1] > 0) { pow[i][0] = 1LL; for (int j = 1; j*i <= k; j++) { pow[i][j] = pow[i][j-1]*((long long)d_max_cnt[i][1]); pow[i][j] %= mod_num; } } } for (int i = 0; i <= k; i++) { d_max[i] = -1; } d_max[0] = 0; cnt[0][0] = 1LL; for (int i = k; i > 1; i--) { if (d_max_cnt[i][1] > 0) { int tmpmax = k/i; for (int j = k-i; j > i; j--) { if (d_max[j] >= 0) { int max = (k-j)/i; for (int p = 1; p <= max; p++) { if (d_max[i*p+j] <= d_max[j]+d_max_cnt[i][0]*p) { int tmpmax = j/(i+1); if (d_max[i*p+j] < d_max[j]+d_max_cnt[i][0]*p) { if (d_max[i*p+j] >= 0) { for (int q = 0; q*i <= i*p+j; q++) { cnt[i*p+j][q] = 0LL; } } d_max[i*p+j] = d_max[j]+d_max_cnt[i][0]*p; } for (int q = 1; q <= tmpmax; q++) { long long tmp = (cnt[j][q]*comb[p+q][p])%mod_num; cnt[i*p+j][p+q] += (tmp*pow[i][p])%mod_num; cnt[i*p+j][p+q] %= mod_num; } } } } } for (int j = 1; j <= tmpmax; j++) { if (d_max[i*j] <= d_max_cnt[i][0]*j) { if (d_max[i*j] < d_max_cnt[i][0]*j) { if (d_max[i*j] >= 0) { for (int q = 0; q <= j; q++) { cnt[i*j][q] = 0LL; } } d_max[i*j] = d_max_cnt[i][0]*j; } cnt[i*j][j] += pow[i][j]; cnt[i*j][j] %= mod_num; } } } } if (d_max_cnt[1][1] > 0) { long long pow = 1LL; for (int i = k; i >= 0; i--) { if (d_max[i] >= 0) { int tmp = d_max[i]+(k-i)*d_max_cnt[1][0]; if (tmp >= max) { if (tmp > max) { max = tmp; ans = 0LL; } } for (int j = 0; j <= i/2; j++) { ans += (((cnt[i][j]*pow)%mod_num)*comb[j+k-i][j])%mod_num; } } pow *= (long long)d_max_cnt[1][1]; pow %= mod_num; } } else { for (int i = 0; i <= k; i++) { if (d_max[i] > max) { max = d_max[i]; ans = 0LL; } if (d_max[i] == max) { for (int j = 0; j <= i; j++) { ans += cnt[i][j]; } } } } printf("%d\n%lld\n", max, ans%mod_num); return 0; }