#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long r = 1, z = x;
  while (y) {
    if (y & 1) r *= z;
    z *= z;
    y = y >> 1;
  }
  return r;
}
long long powerm(long long x, long long y, long long p) {
  long long r = 1;
  while (y) {
    if (y & 1) r = (r * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return r % p;
}
long long modinv(long long x, long long m) { return powerm(x, m - 2, m); }
long long logarithm(long long a, long long b) {
  long long x = 0;
  while (a > 1) {
    x++;
    a /= b;
  }
  return x;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long p[n];
  for (long long i = 0; i < n; i++) cin >> p[i];
  long long a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  long long c1, c2, c3, c4, c5;
  c1 = c2 = c3 = c4 = c5 = 0;
  long long left = 0;
  for (long long i = 0; i < n; i++) {
    left += p[i];
    c5 += left / e;
    left -= left / e * e;
    c4 += left / d;
    left -= left / d * d;
    c3 += left / c;
    left -= left / c * c;
    c2 += left / b;
    left -= left / b * b;
    c1 += left / a;
    left -= left / a * a;
  }
  cout << c1 << " " << c2 << " " << c3 << " " << c4 << " " << c5 << endl
       << left;
  return 0;
}
