#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[50], b[5], ans[5] = {0}, e = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < 5; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    e += a[i];
    for (int j = 4; j >= 0; j--) {
      ans[j] += e / b[j];
      e %= b[j];
    }
  }
  for (int i = 0; i < 5; i++) {
    cout << ans[i] << " ";
  }
  cout << endl << e;
  return 0;
}
