#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T a) {
  return (a >= 0 ? a : -a);
}
int main() {
  int n, p = 0;
  cin >> n;
  long long no[n], cst[5], by[5];
  for (int i = 0; i < n; i++) cin >> no[i];
  for (int i = 0; i < 5; i++) {
    cin >> cst[i];
    by[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    p += no[i];
    int sw, swr;
    for (int j = 4; j >= 0; j--) {
      if (p >= cst[j]) {
        sw = p / cst[j];
        by[j] += sw;
        p = p % cst[j];
      }
    }
  }
  for (int i = 0; i < 5; i++) cout << by[i] << " ";
  cout << "\n" << p;
  return 0;
}
