n, k = map(int, input().split()) c = list(map(int, input().split())) d = list(map(int, input().split())) inf = float("inf") fv = [-inf for i in range(k+1)] fw = [0 for i in range(k+1)] for i in range(n): if c[i] <= k: fv[c[i]] = max(fv[c[i]], d[i]) for i in range(n): if c[i] <= k and fv[c[i]] == d[i]: fw[c[i]] += 1 dpv = [-inf] * (k+1) dpw = [0] * (k+1) dpv[0] = 0 dpw[0] = 1 mod = 998244353 for i in range(1, k+1): for j in range(1, i+1): dpv[i] = max(dpv[i], dpv[i-j] + fv[j]) for j in range(1, i+1): if dpv[i] == fv[j] + dpv[i-j] and dpv[i-j] != -inf: dpw[i] += dpw[i-j] * fw[j] % mod dpw[i] %= mod ansv = max(dpv) print(ansv) answ = 0 for i in range(k+1): if dpv[i] == ansv: answ += dpw[i] answ %= mod print(answ)