#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  long long int i, j, k, n, s = 0;
  cin >> n;
  vector<long long int> a(n), x(5), ans(5, 0);
  for (i = 0; i < (n); ++i) cin >> a[i];
  for (i = 0; i < (5); ++i) cin >> x[i];
  for (i = 0; i < (n); ++i) {
    s = s + a[i];
    for (j = 4; j >= 0; j--) {
      ans[j] += s / x[j];
      s = s % x[j];
    }
  }
  for (i = 0; i < (5); ++i) cout << ans[i] << " ";
  cout << endl << s;
  return 0;
}
