#include <bits/stdc++.h>
using namespace std;
int points[50];
int prizes[5];
long long n[5];
int main() {
  int N;
  scanf("%d", &N);
  long long p = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &points[i]);
  }
  for (int i = 0; i < 5; i++) {
    scanf("%d", &prizes[i]);
  }
  for (int i = 0; i < N; i++) {
    p += (long long)points[i];
    for (int i = 4; i >= 0; i--) {
      long long a = p / prizes[i];
      n[i] += a;
      p -= a * prizes[i];
    }
  }
  printf("%I64d %I64d %I64d %I64d %I64d\n", n[0], n[1], n[2], n[3], n[4], n[5]);
  printf("%I64d", p);
}
