#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, cand = 0;
  cin >> n;
  long long int arr[n + 1];
  long long int prize[6];
  long long int ans[6] = {0};
  for (i = 1; i <= n; i++) cin >> arr[i];
  for (i = 1; i <= 5; i++) cin >> prize[i];
  for (i = 1; i <= n; i++) {
    cand += arr[i];
    for (j = 5; j >= 1; j--) {
      ans[j] += cand / prize[j];
      cand = cand % prize[j];
    }
  }
  for (i = 1; i <= 5; i++) cout << ans[i] << " ";
  cout << endl << cand;
  return 0;
}
