#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long int b[5];
  cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4];
  long long int i = 0, sum = 0;
  long long int count[5];
  for (int i = 0; i < 5; i++) count[i] = 0ll;
  while (i < n) {
    sum += arr[i];
    int j = 4;
    while (j >= 0) {
      if (sum >= b[j]) {
        long long int p = sum / b[j];
        sum -= (p * b[j]);
        count[j] += p;
      } else {
        j--;
      }
    }
    i++;
  }
  for (int i = 0; i <= 4; i++) {
    cout << count[i] << " ";
  }
  cout << "\n";
  cout << sum << "\n";
  return 0;
}
