#include <bits/stdc++.h>
const int MAX = 1e5 + 5;
const int MAX1 = 5e5 + 10;
const int INF = (int)1e9;
const long long INF1 = (long long)1e18;
const int MOD = 7901;
const double eps = 1e-7;
using namespace std;
long long p[MAX];
long long a[MAX];
long long a1[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  long long curp = 0;
  for (int i = 0; i < n; i++) {
    curp += p[i];
    for (int i = 4; i >= 0; i--) {
      if (curp >= a[i]) {
        a1[i] += curp / a[i];
        curp = curp % a[i];
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    cout << a1[i] << ' ';
  }
  cout << "\n";
  cout << curp << '\n';
}
