#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  unsigned n(0);
  cin >> n;
  vector<unsigned long long> array(n);
  for (unsigned it(0); it != n; ++it) {
    cin >> array[it];
  }
  vector<unsigned long long> costs(5);
  for (unsigned it(0); it != 5; ++it) {
    cin >> costs[it];
  }
  long long current(0);
  vector<unsigned long long> counts(5, 0);
  for (unsigned it(0); it != n; ++it) {
    current += array[it];
    bool is_maybe(false);
    do {
      is_maybe = false;
      for (int in(4); in >= 0; --in) {
        if (costs[in] <= current) {
          long long t(current / costs[in]);
          if (t >= 1) {
            current -= t * costs[in];
            counts[in] += t;
            is_maybe = true;
            break;
          }
        }
      }
    } while (is_maybe);
  }
  for (unsigned it(0); it != 5; ++it) {
    cout << counts[it] << " ";
  }
  cout << std::endl << current;
  return 0;
}
