#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
const int INF = 1 << 30;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> p(n);
  for (int i = 0; i < (n); i++) cin >> p[i];
  long long costs[5], ans[5], top = -1;
  for (int i = 0; i < (5); i++) {
    cin >> costs[i];
    top = max(top, costs[i]);
  }
  memset(ans, 0, sizeof(ans));
  long long pts = 0;
  for (int i = 0; i < (n); i++) {
    pts += p[i];
    long long mx, idx;
    do {
      mx = -1;
      for (int j = 0; j < (5); j++)
        if (costs[j] <= pts) {
          mx = max(mx, costs[j]);
          idx = j;
        }
      if (mx != -1) {
        if (mx == top) {
          ans[idx] += pts / top;
          pts -= top * (pts / top);
        } else {
          ans[idx]++;
          pts -= mx;
        }
      }
    } while (mx != -1);
  }
  for (int i = 0; i < (5); i++) cout << ans[i] << " ";
  cout << endl << pts;
  return 0;
}
