#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, sum = 0, temp;
  cin >> n;
  long long A[n], cost[5], prizes[5];
  memset(prizes, 0, sizeof(prizes));
  for (int i = (int)(0); i < (int)(n); i++) cin >> A[i];
  for (int i = (int)(0); i < (int)(5); i++) cin >> cost[i];
  for (int i = (int)(0); i < (int)(n); i++) {
    sum += A[i];
    for (int j = (int)(4); j > (int)(-1); j--) {
      if (sum >= cost[j]) {
        temp = sum / cost[j];
        sum -= cost[j] * temp;
        prizes[j] += temp;
      }
    }
  }
  for (int i = (int)(0); i < (int)(5); i++) cout << prizes[i] << " ";
  cout << endl << sum;
  return 0;
}
