#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  long long points = 0;
  long long a, b, c, d, e;
  long long A = 0, B = 0, C = 0, D = 0, E = 0;
  cin >> a >> b >> c >> d >> e;
  for (int i = 0; i < n; i++) {
    points += p[i];
    E += (points / e);
    points %= e;
    D += (points / d);
    points %= d;
    C += (points / c);
    points %= c;
    B += (points / b);
    points %= b;
    A += (points / a);
    points %= a;
  }
  cout << A << " " << B << " " << C << " " << D << " " << E << endl;
  cout << points << endl;
  return 0;
}
