#include <bits/stdc++.h>
using namespace std;
vector<long long int> point;
long long int total = 0;
long long int temp;
long long int a, b, c, d, e;
long long int a1 = 0;
long long int b1 = 0;
long long int c1 = 0;
long long int d1 = 0;
long long int e1 = 0;
long long int no;
int main() {
  cin >> no;
  for (int i = 0; i < no; i++) {
    cin >> temp;
    point.push_back(temp);
  }
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  for (int i = 0; i < point.size(); i++) {
    total = total + point[i];
    temp = total / e;
    total = total - (e * temp);
    e1 = e1 + temp;
    temp = total / d;
    total = total - (d * temp);
    d1 = d1 + temp;
    temp = total / c;
    total = total - (c * temp);
    c1 = c1 + temp;
    temp = total / b;
    total = total - (b * temp);
    b1 = b1 + temp;
    temp = total / a;
    total = total - (a * temp);
    a1 = a1 + temp;
  }
  cout << a1 << " " << b1 << " " << c1 << " " << d1 << " " << e1 << " " << endl;
  cout << total;
  return 0;
}
