#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int N;
int puntos[50];
int costo[5];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (int i = 0, _n = N; i < _n; i++) cin >> puntos[i];
  for (int i = 0, _n = 5; i < _n; i++) cin >> costo[i];
  vector<long long> cantidad(5, 0LL);
  long long acum = 0;
  for (int i = 0, _n = N; i < _n; i++) {
    acum += puntos[i];
    for (int k = 4; k >= 0; k--) {
      if (acum >= costo[k]) {
        cantidad[k] += acum / costo[k];
        acum = acum % costo[k];
      }
    }
  }
  for (int k = 0, _n = 5; k < _n; k++) {
    if (k) cout << " ";
    cout << cantidad[k];
  }
  cout << endl;
  cout << acum << endl;
}
