#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long sum = 0, arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long price[5], ans[5] = {0};
  for (int i = 0; i < 5; i++) {
    cin >> price[i];
  }
  for (int i = 0; i < n; i++) {
    sum += arr[i];
    while (sum >= price[0]) {
      int j;
      for (j = 0; j < 5; j++) {
        if (price[j] > sum) {
          break;
        }
      }
      j--;
      ans[j] += sum / price[j];
      sum %= price[j];
    }
  }
  for (int i = 0; i < 5; i++) {
    cout << ans[i] << " ";
  }
  cout << endl << sum;
}
