#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> num(n);
    vector<long long> price(5), sol(5, 0);
    long long currentPoints = 0;
    for (int i = 0; i < n; i++) cin >> num[i];
    for (int i = 0; i < 5; i++) cin >> price[i];
    for (int i = 0; i < n; i++) {
      currentPoints += num[i];
      for (int j = 4; j >= 0; j--) {
        long long toAdd = currentPoints / price[j];
        sol[j] += toAdd;
        currentPoints -= toAdd * price[j];
      }
    }
    for (int i = 0; i < 5; i++) {
      if (i) cout << " ";
      cout << sol[i];
    }
    cout << endl << currentPoints << endl;
  }
}
