#include <bits/stdc++.h>
using namespace std;
long long bar[60];
long long price[5];
long long ans[5];
int main() {
  long long n;
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &bar[i]);
  for (int i = 0; i < 5; i++) scanf("%I64d", &price[i]);
  long long point = 0;
  for (int i = 0; i < n; i++) {
    point += bar[i];
    for (int j = 4; j >= 0; j--) {
      if (point % price[j] < point) {
        int dod = point / price[j];
        ans[j] += dod;
        point -= price[j] * dod;
      }
    }
  }
  for (int i = 0; i < 5; i++) printf("%I64d ", ans[i]);
  printf("\n%I64d\n", point);
  return 0;
}
