#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int p[5], f[5];
  for (long long int i = 0; i < 5; i++) {
    cin >> p[i];
    f[i] = 0;
  }
  long long int x = 0;
  for (long long int i = 0; i < n; i++) {
    a[i] += x;
    for (long long int j = 4; j >= 0; j--) {
      if (a[i] >= p[j]) {
        f[j] += a[i] / p[j];
        a[i] = a[i] % p[j];
      }
    }
    x = a[i];
  }
  for (long long int i = 0; i < 5; i++) cout << f[i] << " ";
  cout << "\n";
  cout << x;
  return 0;
}
