#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long array1[n];
  for (int i = 0; i < n; i++) {
    cin >> array1[i];
  }
  long long a, b, c, d, e, sum = 0;
  cin >> a >> b >> c >> d >> e;
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    sum += array1[i];
    mp[5] += sum / e;
    sum %= e;
    mp[4] += sum / d;
    sum %= d;
    mp[3] += sum / c;
    sum %= c;
    mp[2] += sum / b;
    sum %= b;
    mp[1] += sum / a;
    sum %= a;
  }
  for (int i = 1; i <= 5; i++) {
    cout << mp[i];
    if (i != 5) cout << " ";
  }
  cout << endl << sum << endl;
}
