#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
int main() {
  ios_base::sync_with_stdio;
  cin.tie(0);
  int n, t;
  cin >> n;
  vector<int> v(n), p(5);
  map<int, int> b;
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < 5; i++) {
    cin >> p[i];
    b[p[i]] = i;
  }
  sort((p).begin(), (p).end(), greater<int>());
  long long s = 0;
  vector<long long> a(5);
  for (int i = 0; i < n; i++) {
    s += v[i];
    while (s >= p[4]) {
      auto it = lower_bound((p).begin(), (p).end(), s, greater<int>());
      a[b[*it]] += s / (*it);
      s %= *it;
    }
  }
  for (int i = 0; i < 5; i++) cout << a[i] << " ";
  cout << endl << s;
  return 0;
}
