#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, a, b, c, d, e;
  scanf("%d", &n);
  vector<long long int> points(n);
  for (int i = 0; i < n; i++) scanf("%lld", &points[i]);
  scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
  long long int cur = 0;
  vector<long long int> res(5);
  for (int i = 0; i < n; i++) {
    cur += points[i];
    long long int tmp;
    tmp = cur / e;
    res[4] += tmp;
    cur -= tmp * e;
    tmp = cur / d;
    res[3] += tmp;
    cur -= tmp * d;
    tmp = cur / c;
    res[2] += tmp;
    cur -= tmp * c;
    tmp = cur / b;
    res[1] += tmp;
    cur -= tmp * b;
    tmp = cur / a;
    res[0] += tmp;
    cur -= tmp * a;
  }
  for (int i = 0; i < 5; i++) printf("%lld ", res[i]);
  printf("\n%lld\n", cur);
}
