#include <bits/stdc++.h>
using namespace std;
long long int k;
long long int dp[100005][2];
long long int sum[100005];
long long int ans[5];
int32_t main() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> a;
  long long int p[n];
  for (long long int i = 0; i < n; i++) cin >> p[i];
  for (long long int i = 0; i < 5; i++) {
    long long int x;
    cin >> x;
    a.push_back({x, i});
    cerr << "x"
         << ": " << x << " | "
         << "i"
         << ": " << i << '\n';
  }
  sort(a.begin(), a.end());
  for (long long int i = 0; i < 5; i++) {
    long long int x = a[i].first;
    cerr << "x"
         << ": " << x << " | "
         << "a[i].second"
         << ": " << a[i].second << '\n';
  }
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    sum += p[i];
    for (long long int j = 4; j >= 0; j--) {
      if (sum >= a[j].first) {
        long long int s = sum / a[j].first * a[j].first;
        ans[j] += sum / a[j].first;
        sum -= s;
      }
    }
  }
  for (long long int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << '\n' << sum << '\n';
}
