#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 10005, ln = 18;
inline void S(int& n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
const int inf = int(1e9), shift = 30;
long long int a[105], b[5], ans[5];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < 5; i++) cin >> b[i];
  int rem = 0;
  for (int i = 0; i < n; i++) {
    rem += a[i];
    for (int j = 4; j >= 0; j--) {
      if (b[j] <= rem) {
        ans[j] += rem / b[j];
        rem %= b[j];
      }
    }
  }
  for (int i = 0; i < 5; i++) cout << ans[i] << " ";
  cout << endl;
  cout << rem << endl;
  return 0;
}
