#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long p[n];
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  long long a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  long long mugs = 0;
  long long towels = 0;
  long long bags = 0;
  long long bicycles = 0;
  long long cars = 0;
  long long points = 0;
  for (int i = 0; i < n; ++i) {
    points = p[i];
    cars += points / e;
    points %= e;
    bicycles += points / d;
    points %= d;
    bags += points / c;
    points %= c;
    towels += points / b;
    points %= b;
    mugs += points / a;
    points %= a;
    p[i + 1] += points;
  }
  cout << mugs << " ";
  cout << towels << " ";
  cout << bags << " ";
  cout << bicycles << " ";
  cout << cars << "\n";
  cout << points << "\n";
  return 0;
}
