#include <bits/stdc++.h>
using namespace std;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
long long suf(long long x) { return (x * (x + 1)) / 2; }
vector<vector<int> > adj;
const long long mod = 1e9 + 7, size = 1000006, ooi = INT_MAX, ool = INT64_MAX;
int main() {
  int n, m, t;
  while (cin >> n) {
    vector<long long> v(n), sr(5), ans(5);
    vector<long long>::iterator it;
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < 5; i++) cin >> sr[i];
    long long now = 0;
    for (int i = 0; i < n; i++) {
      now += v[i];
      it = upper_bound(((sr).begin()), ((sr).end()), now);
      while (it != sr.begin()) {
        it--;
        ans[(it - sr.begin())] += now / (*it);
        now %= (*it);
        it = upper_bound(((sr).begin()), ((sr).end()), now);
      }
    }
    for (int i = 0; i < 5; i++) cout << ans[i] << " ";
    cout << endl;
    cout << now << endl;
  }
  return 0;
}
