#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = 3.14159265358979323846;
const long long mxN = 3e5 + 2;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> p(n);
  for (long long& x : p) cin >> x;
  long long a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  long long curr = 0;
  long long ga = 0, gb = 0, gc = 0, gd = 0, ge = 0;
  for (long long i = 0; i < n; i++) {
    curr += p[i];
    ge += curr / e;
    curr -= (curr / e) * e;
    gd += curr / d;
    curr -= (curr / d) * d;
    gc += curr / c;
    curr -= (curr / c) * c;
    gb += curr / b;
    curr -= (curr / b) * b;
    ga += curr / a;
    curr -= (curr / a) * a;
  }
  cout << ga << " " << gb << " " << gc << " " << gd << " " << ge << '\n';
  cout << curr;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
