#include <bits/stdc++.h>
using namespace std;
long long n, price[5], cnt[5];
long long update(long long x) {
  for (int i = 4; i >= 0; i--) {
    if (x >= price[i]) {
      cnt[i] += x / price[i];
      x %= price[i];
      if (x)
        return update(x);
      else
        return 0;
    }
  }
  return x;
}
int main() {
  long long x;
  while (cin >> n) {
    vector<int> vec;
    memset(price, 0, sizeof(price));
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++) {
      cin >> x;
      vec.push_back(x);
    }
    for (int i = 0; i < 5; i++) {
      cin >> price[i];
    }
    long long val = 0;
    for (int i = 0; i < vec.size(); i++) {
      val = update(val + vec[i]);
    }
    for (int i = 0; i < 5; i++) {
      cout << cnt[i] << " ";
    }
    cout << "\n" << val << "\n";
  }
  return 0;
}
