#include <bits/stdc++.h>
using namespace std;
int cost[55];
long long a[10], d[10];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> cost[i];
  for (int i = 1; i <= 5; i++) cin >> a[i];
  long long x = 0;
  for (int i = 0; i < n; i++) {
    x += cost[i];
    for (int i = 5; i > 0; i--) {
      if (a[i] <= x) {
        d[i] += x / a[i];
        x = x % a[i];
      }
    }
  }
  for (int i = 1; i <= 5; i++) cout << d[i] << " ";
  printf("\n");
  cout << x;
  return 0;
}
