#include <bits/stdc++.h>
int main() {
  std::set<std::pair<long long, long long>,
           std::greater<std::pair<long long, long long> > >
      prices;
  size_t n;
  std::cin >> n;
  std::vector<long long> p(n);
  for (size_t i = 0; i < n; std::cin >> p[i++])
    ;
  for (size_t i = 0; i < 5; ++i) {
    long long t;
    std::cin >> t;
    prices.insert(std::make_pair(t, i));
  }
  long long res[5] = {0, 0, 0, 0, 0};
  long long sum = 0;
  for (size_t i = 0; i < n; ++i) {
    sum += p[i];
    for (std::set<std::pair<long long, long long>,
                  std::greater<std::pair<long long, long long> > >::iterator i =
             prices.begin();
         i != prices.end(); ++i) {
      res[i->second] += sum / i->first;
      sum %= i->first;
    }
  }
  for (size_t i = 0; i < 5; std::cout << res[i++] << ' ')
    ;
  std::cout << std::endl << sum << std::endl;
  return 0;
}
