#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> s(n);
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) cin >> s[i];
  long long a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  long long r = 0;
  vector<long long> t(5, 0);
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {
    r += s[i];
    if (r >= e) t[4] += r / e, r -= (r / e) * e;
    if (r >= d) t[3] += r / d, r -= (r / d) * d;
    if (r >= c) t[2] += r / c, r -= (r / c) * c;
    if (r >= b) t[1] += r / b, r -= (r / b) * b;
    if (r >= a) t[0] += r / a, r -= (r / a) * a;
  }
  for (int(i) = (int)(0); (i) < (int)(5); ++(i)) cout << t[i] << " ";
  cout << endl;
  cout << r << endl;
  return 0;
}
