#include <bits/stdc++.h>
using namespace std;
int N;
vector<long long> P;
int C[5];
long long X[5];
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> N;
  P = vector<long long>(N);
  for (int i = 0; i < N; ++i) cin >> P[i];
  for (int k = 0; k < 5; ++k) cin >> C[k];
  long long points = 0;
  for (int i = 0; i < N; ++i) {
    points += P[i];
    for (int k = 4; k >= 0; --k) {
      long long m = points / C[k];
      if (m > 0) {
        X[k] += m;
        points -= m * C[k];
      }
    }
  }
  for (int k = 0; k < 5; ++k) {
    if (k > 0) cout << ' ';
    cout << X[k];
  }
  cout << endl;
  cout << points << endl;
  return 0;
}
