#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n;
long long d[((long long)2e5 + 5)];
long long cost[5];
long long remain;
long long ct[5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < 5; ++i) cin >> cost[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 4; j >= 0 && d[i]; --j)
      if (d[i] >= cost[j]) {
        ct[j] += d[i] / cost[j];
        d[i] = d[i] % cost[j];
      }
    d[i + 1] += d[i];
  }
  for (int i = 0; i < 5; ++i) cout << ct[i] << " ";
  cout << "\n" << d[n];
}
