#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const long long MAX64 = 9223372036854775807;
const double PI = 3.14159265358979323846;

int main() {
  long long n, m, sum, min = MAX64, a = 0, b = 0, c = 0, ind;
  cin >> n >> m;
  vector<long long> h(n), w(m), dp(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> w[i];
  }
  sort(h.begin(), h.end());
  h.push_back(MAX64);
  for (int i = 0; i < n; i++) {
    if (i >= 2) {
      c = dp[i - 2];
    }
    if (i % 2) {
      dp[i] = h[i] - a + c;
      b = h[i];
    } else {
      a = h[i];
      dp[i] = h[i] - b + c;
    }
  }
  for (int i = 0; i < m; i++) {
    ind = lower_bound(h.begin(), h.end(), w[i]) - h.begin();
    if (ind >= 2) {
      b = 1;
    } else {
      b = 0;
    }
    if (ind % 2) {
      sum = b * dp[ind - 2] + w[i] - h[ind - 1] + dp[n - 1] - dp[ind - 1];
    } else {
      sum = b * dp[ind - 1] + h[ind] - w[i] + dp[n - 1] - dp[ind];
    }
    if (min > sum) {
      min = sum;
    }
  }
  cout << min << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 2e5 + 5;
const int maxk = 300 + 5;
template<class T> void print(T & x){ cout << x; }
template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; }
template<class T> void print(vector<T> & v) {
    cout << "{";
    if (sz(v)) print(v[0]);
    for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
    cout << "}\n";
}

const int MOD = 998244353;
const int inv2 = (MOD + 1) / 2;

ll A[maxn], f[maxk], rf[maxk], sum[maxk], p[maxk], inv[maxk], pb[maxk], self[maxn][maxk];


inline ll add(ll a, ll b) { // 带减法
    return ((a + b) % MOD + MOD) % MOD;
}
inline ll mul(ll a, ll b) {
    return (a * b) % MOD;
}
ll c(int n, int k) {
    return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k]));
}
ll fpow(ll a, ll n) {
    a %= MOD;
    ll ret = 1;
    for (; n; n >>= 1, a = mul(a, a) )
    	if (n & 1) ret = mul(ret, a);
    return ret;
}
int n, m;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1;i <= n; ++i) {
        cin >> A[i];
    }   
    inv[0] = inv[1] = 1;
    for(int i = 2; i <= max(2,m); ++ i) {
        inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
    }
    f[0] = rf[0] = 1;
    for (int i = 1;i <= m; ++i) {
        f[i] = mul(f[i-1], i);
        rf[i] = mul(rf[i-1], inv[i]);
    }
    for (int i = 1;i <= n; ++i) {
        self[i][0] = 1;
        for (int k = 1;k <= m; ++k) {
            self[i][k] = mul(self[i][k-1], A[i]);
        }
    }
    for (int k = 0;k <= m; ++k) {
        p[k] = 0;
        for (int i = 1;i <= n; ++i) {  
            p[k] = add(p[k], self[i][k]);
        }
    }
    for (int i = 1;i <= m; ++i) {
        pb[i] = mul(p[i], fpow(2, i));
    }

    for (int x = 1; x <= m; ++x) {
        ll ans = 0;
        for (int i = 0;i <= x; ++i) {
            ans = add(ans, mul(c(x, i), mul(p[i], p[x-i])));
        }
        ans = add(ans, -pb[x]);
        ans = mul(ans, inv2);
        cout << ans << endl;
    }
    return 0;
}