#include <bits/stdc++.h>
using namespace std;
const int inf = (int)(1e9) + 100;
const int mod = (int)(1e9) + 7;
const int N = (int)(1e5) + 100;
long long b, c, d, e, n, p[55];
pair<long long, long long> a[10];
long long ans[14];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 1; i <= 5; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + 1 + 5);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    int t = p[i] + cur;
    for (int j = 5; j >= 1; j--) {
      int cnt = t / a[j].first;
      ans[a[j].second] += cnt;
      t -= cnt * a[j].first;
    }
    cur = t;
  }
  for (int i = 1; i <= 5; i++) cout << ans[i] << ' ';
  cout << '\n' << cur;
  return 0;
}
