#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, n, m;
  long long int t;
  cin >> n;
  long long int a[n];
  long long int s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<long long int, long long int>> b;
  for (i = 0; i < 5; i++) {
    cin >> m;
    b.push_back({m, i});
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  long long int c[5] = {0};
  for (j = 0; j < n; j++) {
    s += a[j];
    for (i = 0; i < 5; i++) {
      c[b[i].second] += s / b[i].first;
      s = s % b[i].first;
    }
  }
  for (i = 0; i < 5; i++) cout << c[i] << " ";
  cout << "\n";
  cout << s;
}
