#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int cost[5];
  for (int i = 0; i < 5; i++) cin >> cost[i];
  long long cur = 0;
  long long ans[5];
  memset(ans, 0, sizeof ans);
  for (int i = 0; i < n; i++) {
    cur += p[i];
    while (cur >= cost[0]) {
      for (int j = 4; j >= 0; j--) {
        if (cost[j] <= cur) {
          ans[j] += cur / cost[j];
          cur %= cost[j];
          break;
        }
      }
    }
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << '\n' << cur << '\n';
  return 0;
}
