#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, a[5] = {}, ap[5] = {}, p[55] = {}, bal = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> p[i];
  for (long long i = 0; i < 5; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    bal += p[i];
    for (long long j = 4; j >= 0; j--) {
      if (bal >= a[j]) {
        ap[j] += bal / a[j];
        bal -= (bal / a[j]) * a[j];
      }
    }
  }
  for (long long i = 0; i < 5; i++) cout << ap[i] << " ";
  cout << "\n" << bal << "\n";
  return 0;
}
