#include <bits/stdc++.h>
using namespace std;
long long int n, m, ar[1000005], tut[1000005], p[1000005], sum;
void f() {
  long long int l = 5;
  while (l) {
    long long int x = ar[l];
    if (sum < x) {
      l--;
      continue;
    }
    tut[l] += sum / ar[l];
    sum %= ar[l];
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= 5; i++) cin >> ar[i];
  for (int i = 1; i <= n; i++) {
    sum += p[i];
    f();
  }
  for (int i = 1; i <= 5; i++) cout << tut[i] << " ";
  cout << "\n" << sum;
}
