#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int N = int(2e5 + 7);
int n, p[N], a[5];
long long ans[5], sum;
void solve() {
  for (int i = 4; i >= 0; i--) {
    ans[i] += sum / a[i];
    sum = sum % a[i];
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < 5; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    sum += p[i];
    solve();
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << endl << sum << endl;
  return 0;
}
