#include <bits/stdc++.h>
using namespace std;
string a;
long long n, t, k, d;
int arr[50];
long long c[5], b[5];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < 5; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    k += arr[i];
    for (int j = 4; j >= 0; j--) {
      d = k / b[j];
      c[j] += d;
      k -= d * b[j];
    }
  }
  for (int i = 0; i < 5; i++) {
    cout << c[i] << " ";
  }
  cout << endl;
  cout << k << endl;
}
