#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long *A = new long long[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  long long a, b, c, d, e;
  long long a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0;
  cin >> a >> b >> c >> d >> e;
  unsigned long long sum = 0;
  long long sum1;
  for (int i = 0; i < n; i++) {
    sum += A[i];
    if (sum >= e) {
      sum1 = sum / e;
      sum = sum % e;
      e1 += sum1;
    }
    if (sum >= d) {
      sum1 = sum / d;
      sum = sum % d;
      d1 += sum1;
    }
    if (sum >= c) {
      sum1 = sum / c;
      sum = sum % c;
      c1 += sum1;
    }
    if (sum >= b) {
      sum1 = sum / b;
      sum = sum % b;
      b1 += sum1;
    }
    if (sum >= a) {
      sum1 = sum / a;
      sum = sum % a;
      a1 += sum1;
    }
  }
  cout << a1 << " " << b1 << " " << c1 << " " << d1 << " " << e1 << endl;
  cout << sum << endl;
  return 0;
}
