#include <bits/stdc++.h>
inline long long sbt(long long x) { return __builtin_popcount(x); }
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long res[5];
int32_t main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  long long n;
  cin >> n;
  long long A[n + 13];
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
  }
  long long a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  long long curr = 0;
  for (long long i = 0; i < n; i++) {
    curr += A[i];
    res[4] += curr / e;
    curr = curr % e;
    res[3] += curr / d;
    curr = curr % d;
    res[2] += curr / c;
    curr = curr % c;
    res[1] += curr / b;
    curr = curr % b;
    res[0] += curr / a;
    curr = curr % a;
  }
  for (long long i = 0; i < 5; i++) cout << res[i] << ' ';
  cout << endl;
  cout << curr;
  return 0;
}
