#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long ar[51];
  vector<vector<long long>> price(5);
  long long currentBalance = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < 5; i++) {
    price[i].assign(2, 0);
    cin >> price[i][0];
  }
  for (int i = 0; i < n; i++) {
    currentBalance += ar[i];
    for (int j = 4; j >= 0; j--) {
      int k = currentBalance / price[j][0];
      price[j][1] += k;
      currentBalance -= k * price[j][0];
    }
  }
  for (int i = 0; i < 5; i++) {
    cout << price[i][1] << ' ';
  }
  cout << "\n" << currentBalance;
}
