#include <bits/stdc++.h>
using namespace std;
int n;
long long a[55], b[10], c[10];
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (5); i++) cin >> b[i];
  long long ans = 0;
  for (int i = 0; i < (n); i++) {
    ans += a[i];
    for (int j = 4; j >= 0; j--) {
      if (ans >= b[j]) {
        c[j] += ans / b[j];
        ans %= b[j];
      }
    }
  }
  cout << c[0] << " " << c[1] << " " << c[2] << " " << c[3] << " " << c[4]
       << endl;
  cout << ans << endl;
  return 0;
}
