#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a a, pair b){ if(a.first>b.first) swap(a,b); return max(0, b.first-a.second); } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,d; cin >> n >> d; vector dp(2*n+1,vector(2*n+1, -INFLL)); vector c(2*n+1,vector>(2*n+1)); ll ans = 0; rep(i,n) cin >> dp[i][i+1], dp[n+i][n+i+1] = dp[i][i+1]; rep(i,n){ int x; cin >> x; c[i][i+1] = c[n+i][n+i+1] = {x,x+1}; } for(int i=2;i<=n;i++){ for(int j=0;j<=2*n-i;j++){ for(int k=j+1;k