#include <bits/stdc++.h>
using namespace std;
long long p[5];
long long gp[5];
long long np(long long x) {
  gp[4] += x / p[4], x -= (x / p[4] * p[4]);
  gp[3] += x / p[3], x -= (x / p[3] * p[3]);
  gp[2] += x / p[2], x -= (x / p[2] * p[2]);
  gp[1] += x / p[1], x -= (x / p[1] * p[1]);
  gp[0] += x / p[0], x -= (x / p[0] * p[0]);
  return x;
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4];
  sort(p, p + 5);
  long long m = 0;
  for (int i = 0; i < n; i++) {
    m += a[i];
    m = np(m);
  }
  for (int i = 0; i < 5; i++) cout << gp[i] << " ";
  cout << endl << m << endl;
}
