#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, x, n, i, j;
  cin >> n;
  long long int s[100005];
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  long long int a[10];
  long long int b[10] = {0};
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  long long int rem = 0;
  for (i = 0; i < n; i++) {
    x = rem + s[i];
    for (j = 4; j >= 0; j--) {
      q = x / a[j];
      x = x % a[j];
      b[j] += q;
    }
    rem = x;
  }
  for (i = 0; i < 5; i++) {
    cout << b[i] << " ";
  }
  cout << endl << rem << endl;
  return 0;
}
