#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 5;
long long n, i, j, k = 0, cou = 0, F, gp = 0;
bool min_les(long long a, long long b) { return (abs(gp - a) < abs(gp - b)); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> w, p;
  map<long long, long long> m;
  long long min;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> k;
    w.push_back(k);
  }
  for (i = 0; i < 5; i++) {
    cin >> k;
    p.push_back(k);
  }
  min = *min_element(p.begin(), p.end());
  for (i = 0; i < w.size(); i++) {
    gp += w[i];
    while (gp >= min) {
      k = 0;
      while (p[k] <= gp && k < p.size()) {
        k++;
      }
      k--;
      m[p[k]] += gp / p[k];
      gp = gp % p[k];
    }
  }
  for (i = 0; i < p.size(); i++) {
    cout << m[p[i]] << " ";
  }
  cout << endl;
  cout << gp;
  return 0;
}
