#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> values(55);
  int arr[5];
  long long ans[5] = {0};
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> values[i];
  }
  for (int i = 0; i < 5; ++i) {
    cin >> arr[i];
  }
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += values[i];
    for (int i = 4; i >= 0; --i) {
      ans[i] += sum / arr[i];
      sum %= arr[i];
    }
  }
  for (int i = 0; i < 5; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl << sum << endl;
  return 0;
}
