#include <bits/stdc++.h>
int main() {
  int16_t n;
  std::cin >> n;
  std::vector<uint64_t> values(n), prices(5), pieces(5, 0);
  uint64_t sum = 0;
  for (uint64_t i = 0; i < n; ++i) std::cin >> values[i];
  for (uint64_t i = 0; i < 5; ++i) std::cin >> prices[i];
  for (uint64_t i = 0; i < n; ++i) {
    sum += values[i];
    for (int8_t j = 4; j >= 0; --j)
      while (sum >= prices[j]) {
        pieces[j] += sum / prices[j];
        sum -= prices[j] * (sum / prices[j]);
      }
  }
  for (uint64_t i = 0; i < 5; ++i) std::cout << pieces[i] << " ";
  std::cout << std::endl << sum;
  return 0;
}
