#include <bits/stdc++.h>
using namespace std;
int main() {
  long long nround;
  while (cin >> nround) {
    long long earn[nround];
    long long cost[5];
    long long ans[5];
    long long point = 0;
    long long i, k, m;
    for (i = 0; i < nround; i++) {
      cin >> earn[i];
    }
    for (i = 0; i < 5; i++) {
      cin >> cost[i];
    }
    memset(ans, 0, sizeof(ans));
    for (i = 0; i < nround; i++) {
      point += earn[i];
      while (point >= cost[0]) {
        for (k = 4; k >= 0; k--) {
          if (point / cost[k] > 0) {
            ans[k] = ans[k] + point / cost[k];
            point = point - (point / cost[k] * cost[k]);
            break;
          }
        }
      }
    }
    for (i = 0; i < 4; i++) {
      cout << ans[i] << " ";
    }
    cout << ans[4] << endl;
    cout << point << endl;
  }
  return 0;
}
