#include <bits/stdc++.h>
using namespace std;
void READ(vector<long long> &v, long long n) {
  long long a;
  for (long long i = 0; i < n; i = i + 1) {
    cin >> a;
    v.push_back(a);
  }
}
void PRINT(vector<long long> &v, long long a = 0) {
  for (long long i = a; i < v.size(); i = i + 1) {
    v[i] = max((long long)0, v[i]);
    cout << v[i] << " ";
  }
  cout << "\n";
}
long long n, m, k, l, r;
bool ok = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::floatfield);
  std::cout.precision(15);
  long long a, b, c, d, i, j, t, x, y, z;
  long long p, q, r, u, w;
  char ch, chr;
  string str, st, str1, str2, str3, str4;
  cin >> n;
  vector<long long> v;
  READ(v, n);
  vector<long long> ref;
  vector<long long> dp(5, 0);
  READ(ref, (long long)5);
  c = 0;
  for (int i = 0; i < n; i++) {
    x = v[i];
    c += x;
    while (true) {
      for (j = 0; j < 5; j++) {
        if (ref[j] > c) {
          break;
        }
      }
      if (j) {
        d = c / ref[j - 1];
        dp[j - 1] += d;
        c -= d * ref[j - 1];
      } else {
        break;
      }
    }
  }
  PRINT(dp);
  cout << c;
}
