import sys sys.setrecursionlimit(10**7) def dfs(a, c): if (a, c) in memo: return memo[a, c] n = len(a) if n==1: memo[a, c] = max(a) return memo[a, c] ret = max(a) for i in range(n): if abs(c[i]-c[(i+1)%n])<=K: na = [] nc = [] idx = -1 for j in range(n): if j==i: idx = len(nc) na.append(a[i]+a[(i+1)%n]) nc.append(c[i]) elif j==(i+1)%n: pass else: na.append(a[j]) nc.append(c[j]) if (tuple(na), tuple(nc)) not in memo: memo[(tuple(na), tuple(nc))] = dfs(tuple(na), tuple(nc)) ret1 = memo[(tuple(na), tuple(nc))] ret = max(ret, ret1) nc[idx] = c[(i+1)%n] if (tuple(na), tuple(nc)) not in memo: memo[(tuple(na), tuple(nc))] = dfs(tuple(na), tuple(nc)) ret2 = memo[(tuple(na), tuple(nc))] ret = max(ret, ret2) memo[(a, c)] = ret return memo[(a, c)] N, K = map(int, input().split()) A = tuple(map(int, input().split())) C = tuple(map(int, input().split())) memo = dict() ans = dfs(A, C) print(ans)