#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
const long long inf = 1e18;
inline long long max(long long a, int32_t b) { return a > b ? a : b; }
inline long long max(int32_t a, long long b) { return a > b ? a : b; }
inline long long min(long long a, int32_t b) { return a < b ? a : b; }
inline long long min(int32_t a, long long b) { return a < b ? a : b; }
long long d4_1[4] = {1, 0, -1, 0};
long long d4_2[4] = {0, 1, 0, -1};
long long d8_1[8] = {1, 1, 1, -1, -1, -1, 0, 0};
long long d8_2[8] = {0, -1, 1, 0, -1, 1, 1, -1};
long long seed;
mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long l = 0, long long r = 1e18) {
  return uniform_int_distribution<long long>(l, r)(rng);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n + 5];
    for (long long i = 0; i < n; i++) cin >> arr[i];
    long long brr[5];
    for (long long i = 0; i < 5; i++) cin >> brr[i];
    long long ans[5] = {0};
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      sum += arr[i];
      for (long long j = 4; j >= 0; j--) {
        ans[j] += sum / brr[j];
        sum = sum % brr[j];
      }
    }
    for (long long i = 0; i < 5; i++) cout << ans[i] << " ";
    cout << "\n" << sum << "\n";
  }
}
