#include <bits/stdc++.h>
using namespace std;
long long n, a, b, c, d, e, an[54], ans[5], sum, cnt, o;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> an[i];
  for (int i = 0; i < 5; i++) ans[i] = 0;
  cin >> a >> b >> c >> d >> e;
  sum = 0;
  cnt = 0;
  o = 0;
  while ((cnt < n) or (o == 0)) {
    o = 1;
    sum += an[cnt];
    if (sum >= e) {
      ans[4] += sum / e;
      sum %= e;
    }
    if (sum >= d) {
      ans[3] += sum / d;
      sum %= d;
    }
    if (sum >= c) {
      ans[2] += sum / c;
      sum %= c;
    }
    if (sum >= b) {
      ans[1] += sum / b;
      sum %= b;
    }
    if (sum >= a) {
      ans[0] += sum / a;
      sum %= a;
    }
    cnt++;
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << endl;
  cout << sum;
  return 0;
}
