#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define vi vector<int>
#define vpii vector<pii>
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}

/*
  ######################################################################
  #######################   THE   BIG   INT   ##########################
*/
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
    vector<int> a;
    int sign;
    /*<arpa>*/
    int size(){
    if(a.empty())return 0;
    int ans=(a.size()-1)*base_digits;
    int ca=a.back();
    while(ca)
        ans++,ca/=10;
    return ans;
    }
    bigint operator ^(const bigint &v){
    bigint ans=1,a=*this,b=v;
    while(!b.isZero()){
        if(b%2)
        ans*=a;
        a*=a,b/=2;
    }
    return ans;
    }
    string to_string(){
    stringstream ss;
    ss << *this;
    string s;
    ss >> s;
    return s;
    }
    int sumof(){
    string s = to_string();
    int ans = 0;
    for(auto c : s)  ans += c - '0';
    return ans;
    }
    /*</arpa>*/
    bigint() :
    sign(1) {
    }

    bigint(long long v) {
    *this = v;
    }

    bigint(const string &s) {
    read(s);
    }

    void operator=(const bigint &v) {
    sign = v.sign;
    a = v.a;
    }

    void operator=(long long v) {
    sign = 1;
    a.clear();
    if (v < 0)
        sign = -1, v = -v;
    for (; v > 0; v = v / base)
        a.push_back(v % base);
    }

    bigint operator+(const bigint &v) const {
    if (sign == v.sign) {
        bigint res = v;

        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
        if (i == (int) res.a.size())
            res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
            res.a[i] -= base;
        }
        return res;
    }
    return *this - (-v);
    }

    bigint operator-(const bigint &v) const {
    if (sign == v.sign) {
        if (abs() >= v.abs()) {
        bigint res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = res.a[i] < 0;
            if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
        }
        return -(v - *this);
    }
    return *this + (-v);
    }

    void operator*=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(int v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    void operator*=(long long v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(long long v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
    int norm = base / (b1.a.back() + 1);
    bigint a = a1.abs() * norm;
    bigint b = b1.abs() * norm;
    bigint q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
        r *= base;
        r += a.a[i];
        int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
        int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
        int d = ((long long) base * s1 + s2) / b.a.back();
        r -= b * d;
        while (r < 0)
        r += b, --d;
        q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
    }

    bigint operator/(const bigint &v) const {
    return divmod(*this, v).first;
    }

    bigint operator%(const bigint &v) const {
    return divmod(*this, v).second;
    }

    void operator/=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
        long long cur = a[i] + rem * (long long) base;
        a[i] = (int) (cur / v);
        rem = (int) (cur % v);
    }
    trim();
    }

    bigint operator/(int v) const {
    bigint res = *this;
    res /= v;
    return res;
    }

    int operator%(int v) const {
    if (v < 0)
        v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
        m = (a[i] + m * (long long) base) % v;
    return m * sign;
    }

    void operator+=(const bigint &v) {
    *this = *this + v;
    }
    void operator-=(const bigint &v) {
    *this = *this - v;
    }
    void operator*=(const bigint &v) {
    *this = *this * v;
    }
    void operator/=(const bigint &v) {
    *this = *this / v;
    }

    bool operator<(const bigint &v) const {
    if (sign != v.sign)
        return sign < v.sign;
    if (a.size() != v.a.size())
        return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
        if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
    }

    bool operator>(const bigint &v) const {
    return v < *this;
    }
    bool operator<=(const bigint &v) const {
    return !(v < *this);
    }
    bool operator>=(const bigint &v) const {
    return !(*this < v);
    }
    bool operator==(const bigint &v) const {
    return !(*this < v) && !(v < *this);
    }
    bool operator!=(const bigint &v) const {
    return *this < v || v < *this;
    }

    void trim() {
    while (!a.empty() && !a.back())
        a.pop_back();
    if (a.empty())
        sign = 1;
    }

    bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
    }

    bigint operator-() const {
    bigint res = *this;
    res.sign = -sign;
    return res;
    }

    bigint abs() const {
    bigint res = *this;
    res.sign *= res.sign;
    return res;
    }

    long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
        res = res * base + a[i];
    return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
    return b.isZero() ? a : gcd(b, a % b);
    }
    friend bigint lcm(const bigint &a, const bigint &b) {
    return a / gcd(a, b) * b;
    }

    void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
        if (s[pos] == '-')
        sign = -sign;
        ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
        int x = 0;
        for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
        a.push_back(x);
    }
    trim();
    }

    friend istream& operator>>(istream &stream, bigint &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
    }

    friend ostream& operator<<(ostream &stream, const bigint &v) {
    if (v.sign == -1)
        stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
        stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
        p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        cur += a[i] * p[cur_digits];
        cur_digits += old_digits;
        while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
        }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
        res.pop_back();
    return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res[i + j] += a[i] * b[j];
        return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
        a2[i] += a1[i];
    for (int i = 0; i < k; i++)
        b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
        r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
        res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
        res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        res[i + n] += a2b2[i];
    return res;
    }

    bigint operator*(const bigint &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
        a.push_back(0);
    while (b.size() < a.size())
        b.push_back(0);
    while (a.size() & (a.size() - 1))
        a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    bigint res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
        long long cur = c[i] + carry;
        res.a.push_back((int) (cur % 1000000));
        carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
    }
};
/*
  #######################   THE   BIG   INT   ##########################
  ######################################################################
*/

/*---------------------------------------------------START-CODE------------------------------------------------------*/
int n;
int p[55];
int prizes[5];
lli freq[5];
int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>p[i];
    cin>>prizes[0]>>prizes[1]>>prizes[2]>>prizes[3]>>prizes[4];
    freq[0] =freq[1]=freq[2]=freq[3]=freq[4] = 0;
    lli sum = 0;
    for(int i = 1;i<=n;i++){
        sum += p[i];
        for(int j = 4;j>=0;j--){
            while(sum >=prizes[j]){
                sum -= prizes[j];
                freq[j]++;
            }
        }
    }

    for(int i = 0;i<5;i++)
        cout<<freq[i]<<" ";
    cout<<endl;
    cout<<sum<<endl;

    // cout<<"Execution time : "<<tick()<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define vi vector<int>
#define vpii vector<pii>
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}

/*
  ######################################################################
  #######################   THE   BIG   INT   ##########################
*/
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
    vector<int> a;
    int sign;
    /*<arpa>*/
    int size(){
    if(a.empty())return 0;
    int ans=(a.size()-1)*base_digits;
    int ca=a.back();
    while(ca)
        ans++,ca/=10;
    return ans;
    }
    bigint operator ^(const bigint &v){
    bigint ans=1,a=*this,b=v;
    while(!b.isZero()){
        if(b%2)
        ans*=a;
        a*=a,b/=2;
    }
    return ans;
    }
    string to_string(){
    stringstream ss;
    ss << *this;
    string s;
    ss >> s;
    return s;
    }
    int sumof(){
    string s = to_string();
    int ans = 0;
    for(auto c : s)  ans += c - '0';
    return ans;
    }
    /*</arpa>*/
    bigint() :
    sign(1) {
    }

    bigint(long long v) {
    *this = v;
    }

    bigint(const string &s) {
    read(s);
    }

    void operator=(const bigint &v) {
    sign = v.sign;
    a = v.a;
    }

    void operator=(long long v) {
    sign = 1;
    a.clear();
    if (v < 0)
        sign = -1, v = -v;
    for (; v > 0; v = v / base)
        a.push_back(v % base);
    }

    bigint operator+(const bigint &v) const {
    if (sign == v.sign) {
        bigint res = v;

        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
        if (i == (int) res.a.size())
            res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
            res.a[i] -= base;
        }
        return res;
    }
    return *this - (-v);
    }

    bigint operator-(const bigint &v) const {
    if (sign == v.sign) {
        if (abs() >= v.abs()) {
        bigint res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = res.a[i] < 0;
            if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
        }
        return -(v - *this);
    }
    return *this + (-v);
    }

    void operator*=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(int v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    void operator*=(long long v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(long long v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
    int norm = base / (b1.a.back() + 1);
    bigint a = a1.abs() * norm;
    bigint b = b1.abs() * norm;
    bigint q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
        r *= base;
        r += a.a[i];
        int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
        int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
        int d = ((long long) base * s1 + s2) / b.a.back();
        r -= b * d;
        while (r < 0)
        r += b, --d;
        q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
    }

    bigint operator/(const bigint &v) const {
    return divmod(*this, v).first;
    }

    bigint operator%(const bigint &v) const {
    return divmod(*this, v).second;
    }

    void operator/=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
        long long cur = a[i] + rem * (long long) base;
        a[i] = (int) (cur / v);
        rem = (int) (cur % v);
    }
    trim();
    }

    bigint operator/(int v) const {
    bigint res = *this;
    res /= v;
    return res;
    }

    int operator%(int v) const {
    if (v < 0)
        v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
        m = (a[i] + m * (long long) base) % v;
    return m * sign;
    }

    void operator+=(const bigint &v) {
    *this = *this + v;
    }
    void operator-=(const bigint &v) {
    *this = *this - v;
    }
    void operator*=(const bigint &v) {
    *this = *this * v;
    }
    void operator/=(const bigint &v) {
    *this = *this / v;
    }

    bool operator<(const bigint &v) const {
    if (sign != v.sign)
        return sign < v.sign;
    if (a.size() != v.a.size())
        return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
        if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
    }

    bool operator>(const bigint &v) const {
    return v < *this;
    }
    bool operator<=(const bigint &v) const {
    return !(v < *this);
    }
    bool operator>=(const bigint &v) const {
    return !(*this < v);
    }
    bool operator==(const bigint &v) const {
    return !(*this < v) && !(v < *this);
    }
    bool operator!=(const bigint &v) const {
    return *this < v || v < *this;
    }

    void trim() {
    while (!a.empty() && !a.back())
        a.pop_back();
    if (a.empty())
        sign = 1;
    }

    bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
    }

    bigint operator-() const {
    bigint res = *this;
    res.sign = -sign;
    return res;
    }

    bigint abs() const {
    bigint res = *this;
    res.sign *= res.sign;
    return res;
    }

    long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
        res = res * base + a[i];
    return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
    return b.isZero() ? a : gcd(b, a % b);
    }
    friend bigint lcm(const bigint &a, const bigint &b) {
    return a / gcd(a, b) * b;
    }

    void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
        if (s[pos] == '-')
        sign = -sign;
        ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
        int x = 0;
        for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
        a.push_back(x);
    }
    trim();
    }

    friend istream& operator>>(istream &stream, bigint &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
    }

    friend ostream& operator<<(ostream &stream, const bigint &v) {
    if (v.sign == -1)
        stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
        stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
        p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        cur += a[i] * p[cur_digits];
        cur_digits += old_digits;
        while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
        }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
        res.pop_back();
    return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res[i + j] += a[i] * b[j];
        return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
        a2[i] += a1[i];
    for (int i = 0; i < k; i++)
        b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
        r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
        res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
        res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        res[i + n] += a2b2[i];
    return res;
    }

    bigint operator*(const bigint &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
        a.push_back(0);
    while (b.size() < a.size())
        b.push_back(0);
    while (a.size() & (a.size() - 1))
        a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    bigint res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
        long long cur = c[i] + carry;
        res.a.push_back((int) (cur % 1000000));
        carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
    }
};
/*
  #######################   THE   BIG   INT   ##########################
  ######################################################################
*/

/*---------------------------------------------------START-CODE------------------------------------------------------*/
int n;
int p[55];
int prizes[5];
lli freq[5];
int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>p[i];
    cin>>prizes[0]>>prizes[1]>>prizes[2]>>prizes[3]>>prizes[4];
    freq[0] =freq[1]=freq[2]=freq[3]=freq[4] = 0;
    lli sum = 0;
    for(int i = 1;i<=n;i++){
        sum += p[i];
        for(int j = 4;j>=0;j--){
            if(sum/prizes[j] >= 1){
                lli k = sum/prizes[j];
                //cout<<k<<endl;
                sum -= k*prizes[j];
                freq[j] += k;
            }
        }
    }

    for(int i = 0;i<5;i++)
        cout<<freq[i]<<" ";
    cout<<endl;
    cout<<sum<<endl;

    // cout<<"Execution time : "<<tick()<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define vi vector<int>
#define vpii vector<pii>
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}

/*
  ######################################################################
  #######################   THE   BIG   INT   ##########################
*/
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
    vector<int> a;
    int sign;
    /*<arpa>*/
    int size(){
    if(a.empty())return 0;
    int ans=(a.size()-1)*base_digits;
    int ca=a.back();
    while(ca)
        ans++,ca/=10;
    return ans;
    }
    bigint operator ^(const bigint &v){
    bigint ans=1,a=*this,b=v;
    while(!b.isZero()){
        if(b%2)
        ans*=a;
        a*=a,b/=2;
    }
    return ans;
    }
    string to_string(){
    stringstream ss;
    ss << *this;
    string s;
    ss >> s;
    return s;
    }
    int sumof(){
    string s = to_string();
    int ans = 0;
    for(auto c : s)  ans += c - '0';
    return ans;
    }
    /*</arpa>*/
    bigint() :
    sign(1) {
    }

    bigint(long long v) {
    *this = v;
    }

    bigint(const string &s) {
    read(s);
    }

    void operator=(const bigint &v) {
    sign = v.sign;
    a = v.a;
    }

    void operator=(long long v) {
    sign = 1;
    a.clear();
    if (v < 0)
        sign = -1, v = -v;
    for (; v > 0; v = v / base)
        a.push_back(v % base);
    }

    bigint operator+(const bigint &v) const {
    if (sign == v.sign) {
        bigint res = v;

        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
        if (i == (int) res.a.size())
            res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
            res.a[i] -= base;
        }
        return res;
    }
    return *this - (-v);
    }

    bigint operator-(const bigint &v) const {
    if (sign == v.sign) {
        if (abs() >= v.abs()) {
        bigint res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = res.a[i] < 0;
            if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
        }
        return -(v - *this);
    }
    return *this + (-v);
    }

    void operator*=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(int v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    void operator*=(long long v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(long long v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
    int norm = base / (b1.a.back() + 1);
    bigint a = a1.abs() * norm;
    bigint b = b1.abs() * norm;
    bigint q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
        r *= base;
        r += a.a[i];
        int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
        int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
        int d = ((long long) base * s1 + s2) / b.a.back();
        r -= b * d;
        while (r < 0)
        r += b, --d;
        q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
    }

    bigint operator/(const bigint &v) const {
    return divmod(*this, v).first;
    }

    bigint operator%(const bigint &v) const {
    return divmod(*this, v).second;
    }

    void operator/=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
        long long cur = a[i] + rem * (long long) base;
        a[i] = (int) (cur / v);
        rem = (int) (cur % v);
    }
    trim();
    }

    bigint operator/(int v) const {
    bigint res = *this;
    res /= v;
    return res;
    }

    int operator%(int v) const {
    if (v < 0)
        v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
        m = (a[i] + m * (long long) base) % v;
    return m * sign;
    }

    void operator+=(const bigint &v) {
    *this = *this + v;
    }
    void operator-=(const bigint &v) {
    *this = *this - v;
    }
    void operator*=(const bigint &v) {
    *this = *this * v;
    }
    void operator/=(const bigint &v) {
    *this = *this / v;
    }

    bool operator<(const bigint &v) const {
    if (sign != v.sign)
        return sign < v.sign;
    if (a.size() != v.a.size())
        return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
        if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
    }

    bool operator>(const bigint &v) const {
    return v < *this;
    }
    bool operator<=(const bigint &v) const {
    return !(v < *this);
    }
    bool operator>=(const bigint &v) const {
    return !(*this < v);
    }
    bool operator==(const bigint &v) const {
    return !(*this < v) && !(v < *this);
    }
    bool operator!=(const bigint &v) const {
    return *this < v || v < *this;
    }

    void trim() {
    while (!a.empty() && !a.back())
        a.pop_back();
    if (a.empty())
        sign = 1;
    }

    bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
    }

    bigint operator-() const {
    bigint res = *this;
    res.sign = -sign;
    return res;
    }

    bigint abs() const {
    bigint res = *this;
    res.sign *= res.sign;
    return res;
    }

    long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
        res = res * base + a[i];
    return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
    return b.isZero() ? a : gcd(b, a % b);
    }
    friend bigint lcm(const bigint &a, const bigint &b) {
    return a / gcd(a, b) * b;
    }

    void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
        if (s[pos] == '-')
        sign = -sign;
        ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
        int x = 0;
        for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
        a.push_back(x);
    }
    trim();
    }

    friend istream& operator>>(istream &stream, bigint &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
    }

    friend ostream& operator<<(ostream &stream, const bigint &v) {
    if (v.sign == -1)
        stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
        stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
        p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        cur += a[i] * p[cur_digits];
        cur_digits += old_digits;
        while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
        }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
        res.pop_back();
    return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res[i + j] += a[i] * b[j];
        return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
        a2[i] += a1[i];
    for (int i = 0; i < k; i++)
        b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
        r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
        res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
        res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        res[i + n] += a2b2[i];
    return res;
    }

    bigint operator*(const bigint &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
        a.push_back(0);
    while (b.size() < a.size())
        b.push_back(0);
    while (a.size() & (a.size() - 1))
        a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    bigint res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
        long long cur = c[i] + carry;
        res.a.push_back((int) (cur % 1000000));
        carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
    }
};
/*
  #######################   THE   BIG   INT   ##########################
  ######################################################################
*/

/*---------------------------------------------------START-CODE------------------------------------------------------*/
int n;
int p[55];
int prizes[5];
int freq[55];
int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>p[i];
    cin>>prizes[0]>>prizes[1]>>prizes[2]>>prizes[3]>>prizes[4];
    memset(freq,0,sizeof(freq));
    int sum = 0;
    for(int i = 1;i<=n;i++){
        sum += p[i];
        for(int j = 4;j>=0;j--){
            while(sum >=prizes[j]){
                sum -= prizes[j];
                freq[j]++;
            }
        }
    }

    for(int i = 0;i<5;i++)
        cout<<freq[i]<<" ";
    cout<<endl;
    cout<<sum<<endl;

    // cout<<"Execution time : "<<tick()<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define vi vector<int>
#define vpii vector<pii>
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}

/*
  ######################################################################
  #######################   THE   BIG   INT   ##########################
*/
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
    vector<int> a;
    int sign;
    /*<arpa>*/
    int size(){
    if(a.empty())return 0;
    int ans=(a.size()-1)*base_digits;
    int ca=a.back();
    while(ca)
        ans++,ca/=10;
    return ans;
    }
    bigint operator ^(const bigint &v){
    bigint ans=1,a=*this,b=v;
    while(!b.isZero()){
        if(b%2)
        ans*=a;
        a*=a,b/=2;
    }
    return ans;
    }
    string to_string(){
    stringstream ss;
    ss << *this;
    string s;
    ss >> s;
    return s;
    }
    int sumof(){
    string s = to_string();
    int ans = 0;
    for(auto c : s)  ans += c - '0';
    return ans;
    }
    /*</arpa>*/
    bigint() :
    sign(1) {
    }

    bigint(long long v) {
    *this = v;
    }

    bigint(const string &s) {
    read(s);
    }

    void operator=(const bigint &v) {
    sign = v.sign;
    a = v.a;
    }

    void operator=(long long v) {
    sign = 1;
    a.clear();
    if (v < 0)
        sign = -1, v = -v;
    for (; v > 0; v = v / base)
        a.push_back(v % base);
    }

    bigint operator+(const bigint &v) const {
    if (sign == v.sign) {
        bigint res = v;

        for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
        if (i == (int) res.a.size())
            res.a.push_back(0);
        res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
        carry = res.a[i] >= base;
        if (carry)
            res.a[i] -= base;
        }
        return res;
    }
    return *this - (-v);
    }

    bigint operator-(const bigint &v) const {
    if (sign == v.sign) {
        if (abs() >= v.abs()) {
        bigint res = *this;
        for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
            res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
            carry = res.a[i] < 0;
            if (carry)
            res.a[i] += base;
        }
        res.trim();
        return res;
        }
        return -(v - *this);
    }
    return *this + (-v);
    }

    void operator*=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(int v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    void operator*=(long long v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
        if (i == (int) a.size())
        a.push_back(0);
        long long cur = a[i] * (long long) v + carry;
        carry = (int) (cur / base);
        a[i] = (int) (cur % base);
        //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
    }
    trim();
    }

    bigint operator*(long long v) const {
    bigint res = *this;
    res *= v;
    return res;
    }

    friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
    int norm = base / (b1.a.back() + 1);
    bigint a = a1.abs() * norm;
    bigint b = b1.abs() * norm;
    bigint q, r;
    q.a.resize(a.a.size());

    for (int i = a.a.size() - 1; i >= 0; i--) {
        r *= base;
        r += a.a[i];
        int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
        int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
        int d = ((long long) base * s1 + s2) / b.a.back();
        r -= b * d;
        while (r < 0)
        r += b, --d;
        q.a[i] = d;
    }

    q.sign = a1.sign * b1.sign;
    r.sign = a1.sign;
    q.trim();
    r.trim();
    return make_pair(q, r / norm);
    }

    bigint operator/(const bigint &v) const {
    return divmod(*this, v).first;
    }

    bigint operator%(const bigint &v) const {
    return divmod(*this, v).second;
    }

    void operator/=(int v) {
    if (v < 0)
        sign = -sign, v = -v;
    for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
        long long cur = a[i] + rem * (long long) base;
        a[i] = (int) (cur / v);
        rem = (int) (cur % v);
    }
    trim();
    }

    bigint operator/(int v) const {
    bigint res = *this;
    res /= v;
    return res;
    }

    int operator%(int v) const {
    if (v < 0)
        v = -v;
    int m = 0;
    for (int i = a.size() - 1; i >= 0; --i)
        m = (a[i] + m * (long long) base) % v;
    return m * sign;
    }

    void operator+=(const bigint &v) {
    *this = *this + v;
    }
    void operator-=(const bigint &v) {
    *this = *this - v;
    }
    void operator*=(const bigint &v) {
    *this = *this * v;
    }
    void operator/=(const bigint &v) {
    *this = *this / v;
    }

    bool operator<(const bigint &v) const {
    if (sign != v.sign)
        return sign < v.sign;
    if (a.size() != v.a.size())
        return a.size() * sign < v.a.size() * v.sign;
    for (int i = a.size() - 1; i >= 0; i--)
        if (a[i] != v.a[i])
        return a[i] * sign < v.a[i] * sign;
    return false;
    }

    bool operator>(const bigint &v) const {
    return v < *this;
    }
    bool operator<=(const bigint &v) const {
    return !(v < *this);
    }
    bool operator>=(const bigint &v) const {
    return !(*this < v);
    }
    bool operator==(const bigint &v) const {
    return !(*this < v) && !(v < *this);
    }
    bool operator!=(const bigint &v) const {
    return *this < v || v < *this;
    }

    void trim() {
    while (!a.empty() && !a.back())
        a.pop_back();
    if (a.empty())
        sign = 1;
    }

    bool isZero() const {
    return a.empty() || (a.size() == 1 && !a[0]);
    }

    bigint operator-() const {
    bigint res = *this;
    res.sign = -sign;
    return res;
    }

    bigint abs() const {
    bigint res = *this;
    res.sign *= res.sign;
    return res;
    }

    long long longValue() const {
    long long res = 0;
    for (int i = a.size() - 1; i >= 0; i--)
        res = res * base + a[i];
    return res * sign;
    }

    friend bigint gcd(const bigint &a, const bigint &b) {
    return b.isZero() ? a : gcd(b, a % b);
    }
    friend bigint lcm(const bigint &a, const bigint &b) {
    return a / gcd(a, b) * b;
    }

    void read(const string &s) {
    sign = 1;
    a.clear();
    int pos = 0;
    while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
        if (s[pos] == '-')
        sign = -sign;
        ++pos;
    }
    for (int i = s.size() - 1; i >= pos; i -= base_digits) {
        int x = 0;
        for (int j = max(pos, i - base_digits + 1); j <= i; j++)
        x = x * 10 + s[j] - '0';
        a.push_back(x);
    }
    trim();
    }

    friend istream& operator>>(istream &stream, bigint &v) {
    string s;
    stream >> s;
    v.read(s);
    return stream;
    }

    friend ostream& operator<<(ostream &stream, const bigint &v) {
    if (v.sign == -1)
        stream << '-';
    stream << (v.a.empty() ? 0 : v.a.back());
    for (int i = (int) v.a.size() - 2; i >= 0; --i)
        stream << setw(base_digits) << setfill('0') << v.a[i];
    return stream;
    }

    static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
    vector<long long> p(max(old_digits, new_digits) + 1);
    p[0] = 1;
    for (int i = 1; i < (int) p.size(); i++)
        p[i] = p[i - 1] * 10;
    vector<int> res;
    long long cur = 0;
    int cur_digits = 0;
    for (int i = 0; i < (int) a.size(); i++) {
        cur += a[i] * p[cur_digits];
        cur_digits += old_digits;
        while (cur_digits >= new_digits) {
        res.push_back(int(cur % p[new_digits]));
        cur /= p[new_digits];
        cur_digits -= new_digits;
        }
    }
    res.push_back((int) cur);
    while (!res.empty() && !res.back())
        res.pop_back();
    return res;
    }

    typedef vector<long long> vll;

    static vll karatsubaMultiply(const vll &a, const vll &b) {
    int n = a.size();
    vll res(n + n);
    if (n <= 32) {
        for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res[i + j] += a[i] * b[j];
        return res;
    }

    int k = n >> 1;
    vll a1(a.begin(), a.begin() + k);
    vll a2(a.begin() + k, a.end());
    vll b1(b.begin(), b.begin() + k);
    vll b2(b.begin() + k, b.end());

    vll a1b1 = karatsubaMultiply(a1, b1);
    vll a2b2 = karatsubaMultiply(a2, b2);

    for (int i = 0; i < k; i++)
        a2[i] += a1[i];
    for (int i = 0; i < k; i++)
        b2[i] += b1[i];

    vll r = karatsubaMultiply(a2, b2);
    for (int i = 0; i < (int) a1b1.size(); i++)
        r[i] -= a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        r[i] -= a2b2[i];

    for (int i = 0; i < (int) r.size(); i++)
        res[i + k] += r[i];
    for (int i = 0; i < (int) a1b1.size(); i++)
        res[i] += a1b1[i];
    for (int i = 0; i < (int) a2b2.size(); i++)
        res[i + n] += a2b2[i];
    return res;
    }

    bigint operator*(const bigint &v) const {
    vector<int> a6 = convert_base(this->a, base_digits, 6);
    vector<int> b6 = convert_base(v.a, base_digits, 6);
    vll a(a6.begin(), a6.end());
    vll b(b6.begin(), b6.end());
    while (a.size() < b.size())
        a.push_back(0);
    while (b.size() < a.size())
        b.push_back(0);
    while (a.size() & (a.size() - 1))
        a.push_back(0), b.push_back(0);
    vll c = karatsubaMultiply(a, b);
    bigint res;
    res.sign = sign * v.sign;
    for (int i = 0, carry = 0; i < (int) c.size(); i++) {
        long long cur = c[i] + carry;
        res.a.push_back((int) (cur % 1000000));
        carry = (int) (cur / 1000000);
    }
    res.a = convert_base(res.a, 6, base_digits);
    res.trim();
    return res;
    }
};
/*
  #######################   THE   BIG   INT   ##########################
  ######################################################################
*/

/*---------------------------------------------------START-CODE------------------------------------------------------*/
int n;
int p[55];
int prizes[5];
lli freq[5];
int main(){
    fastio;
    cin>>n;
    for(int i = 1;i<=n;i++)
        cin>>p[i];
    cin>>prizes[0]>>prizes[1]>>prizes[2]>>prizes[3]>>prizes[4];
    freq[0] =freq[1]=freq[2]=freq[3]=freq[4] = 0;
    lli sum = 0;
    for(int i = 1;i<=n;i++){
        sum += p[i];
        for(int j = 4;j>=0;j--){
            if(sum/prizes[j] >= 1){
                lli k = sum/prizes[j];
                cout<<k<<endl;
                sum -= k*prizes[j];
                freq[j] += k;
            }
        }
    }

    for(int i = 0;i<5;i++)
        cout<<freq[i]<<" ";
    cout<<endl;
    cout<<sum<<endl;

    // cout<<"Execution time : "<<tick()<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<long long int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	long long prize[5];
	long long cnt[5];
	for(int i=0;i<5;i++){
		cin>>prize[i];
		cnt[i]=0;
	}
	long long rem=0;
	for(int i=0;i<n;i++){
		// cerr<<i<<" "<<endl;
		rem+=v[i];
		cnt[4]+=rem/prize[4];
		rem-=(rem/prize[4])*prize[4];
		while(1){
			int idx=upper_bound(prize,prize+5,rem)-prize-1;
			if(idx==-1){
				break;
			}
			else{
				rem-=prize[idx];
				cnt[idx]++;
			}
		}
	}
	for(int i=0;i<5;i++){
		cout<<cnt[i]<<" ";
	}
	cout<<endl;
	cout<<rem;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<long long int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	long long prize[5];
	long long cnt[5];
	for(int i=0;i<5;i++){
		cin>>prize[i];
		cnt[i]=0;
	}
	long long rem=0;
	for(int i=0;i<n;i++){
			// cerr<<i<<" "<<endl;
		rem+=v[i];
		while(1){
			int idx=upper_bound(prize,prize+5,rem)-prize-1;
			if(idx==-1){
				break;
			}
			else{
				rem-=prize[idx];
				cnt[idx]++;
			}
		}
	}
	for(int i=0;i<5;i++){
		cout<<cnt[i]<<" ";
	}
	cout<<endl;
	cout<<rem;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<long long int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	long long prize[5];
	long long cnt[5];
	for(int i=0;i<5;i++){
		cin>>prize[i];
		cnt[i]=0;
	}
	long long rem=0;
	for(int i=0;i<n;i++){
			// cerr<<i<<" "<<endl;
		rem+=v[i];
		while(1){
			int idx=upper_bound(prize,prize+5,rem)-prize-1;
			if(idx==-1){
				break;
			}
			else{
				rem-=prize[idx];
				cnt[idx]++;
			}
		}
	}
	for(int i=0;i<5;i++){
		cout<<cnt[i]<<" ";
	}
}


//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <bitset>

using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
const double EPS = 1e-12;
typedef long long ll;
const double PI = 3.14159265359;
enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll x[100], acm[6], cnt[5];
int n;
map<int, int>mp;
int solve(int nn){

	for (int j = 4; j >= 0; j--)
	{

			cnt[j] += nn / acm[j];
			nn %= acm[j];

	}
	return nn;
}
int main(){

	Compiler_Beso

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < 5; i++)
		cin >> acm[i];
	ll s = 0;
	for (int i = 0; i < n; i++)
	{
		s += x[i];
		s = solve(s);
	}
	for (int i = 0; i < 5; i++)
		cout << cnt[i] << " ";
	cout << "\n" << s;

	return 0;
}


//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <bitset>

using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
const double EPS = 1e-12;
typedef long long ll;
const double PI = 3.14159265359;
enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll x[100], acm[6], cnt[5];
int n;
map<int, int>mp;
int solve(int nn){

	for (int j = 0; j < 6; j++)
	{
		if (nn && nn <= acm[j])
		{
			int id = j&&acm[j] != nn ? j - 1 : j;
			cnt[id] += nn / acm[id];
			//cout << nn / acm[id] << " " << acm[id] << endl;
			nn %= acm[id];

		}
	}
	if (nn >= acm[0] && (!x[n] || !mp[nn+x[n]]))
		nn=solve(nn);
	return nn;
}
int main(){

	Compiler_Beso

	cin >> n;
	acm[5] = 1e9 + 2;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < 5; i++)
		cin >> acm[i],mp[acm[i]]=1;
	for (int i = 0; i <= n; i++)
	{

		if (i!=n)
			x[n] += solve(x[i]);
		else
			x[n] = solve(x[i]);
	}
	for (int i = 0; i < 5; i++)
		cout << cnt[i] << " ";
	cout << "\n" << x[n];

	return 0;
}


//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <bitset>

using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
const double EPS = 1e-12;
typedef long long ll;
const double PI = 3.14159265359;
enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll x[100], acm[6], cnt[5];
int n;
map<int, int>mp;
int solve(int nn){

	for (int j = 4; j >= 0; j--)
	{

			cnt[j] += nn / acm[j];
			nn %= acm[j];

	}
	return nn;
}
int main(){

	Compiler_Beso

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < 5; i++)
		cin >> acm[i];
	ll s = 0;
	for (int i = 0; i < n; i++)
	{
		s += x[i];
		s = solve(s);
	}
	for (int i = 0; i < 5; i++)
		cout << cnt[i] << " ";
	cout << "\n" << x[n];

	return 0;
}


//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <bitset>

using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
const double EPS = 1e-12;
typedef long long ll;
const double PI = 3.14159265359;
enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll x[100], acm[6], cnt[5];
int n;
map<int, int>mp;
int solve(int nn){

	for (int j = 4; j >= 0; j--)
	{

			cnt[j] += nn / acm[j];
			nn %= acm[j];

	}
	return nn;
}
int main(){

	Compiler_Beso

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < 5; i++)
		cin >> acm[i];
	ll s = 0;
	for (int i = 0; i < n; i++)
	{
		s += x[i];
		s = solve(s);
	}
	s = solve(s);
	for (int i = 0; i < 5; i++)
		cout << cnt[i] << " ";
	cout << "\n" << s;

	return 0;
}


//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <climits>
#include <bitset>

using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
const double EPS = 1e-12;
typedef long long ll;
const double PI = 3.14159265359;
enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll x[100], acm[6], cnt[5];
int solve(int x){
	bool f = 0;
	for (int j = 0; j < 6; j++)
	{
		if (x&&x <= acm[j])
		{
			f = 1;
			int id = j&&acm[j] != x ? j - 1 : j;
			cnt[id] += x / acm[id];
			x %= acm[id];
		}
	}
	return x;
}
int main(){

	Compiler_Beso

		int n;
	cin >> n;
	acm[5] = 1e9 + 2;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < 5; i++)
		cin >> acm[i];
	for (int i = 0; i <= n; i++)
	{

		if (x[i] >= acm[0])
		{
			x[i] = solve(x[i]);
			i -= 1;
		}
		else
			x[n] += i == n ? 0 : x[i];
	}
	for (int i = 0; i < 5; i++)
		cout << cnt[i] << " ";
	cout << "\n" << x[n];

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(0);
	int n;
	cin>>n;
	long int p[n];
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	long int prize[5];
	for(int i=0; i<5; i++){
		cin>>prize[i];
	}
	for(int i=1; i<n; i++){
		p[i]+=p[i-1];
	}
	long long int cost=0;
	map<long int, long int> count;
	for(int i=0; i<5; i++){
		count.insert(make_pair(prize[i], 0));
	}
	for(int i=0; i<n; i++){
		long int temp=p[i]-cost;
//		long int value=*prev(upper_bound(prize, prize+n, (temp-cost)));
//		cout<<value<<endl;
//		cout<<temp<<endl;
		while(temp>=prize[0]){
			long int value=*prev(upper_bound(prize, prize+5, temp));
			long int valuecount=temp/value;
			long int next=temp-(valuecount*value);
			count[value]+=valuecount;
			cost+=valuecount*value;
//			cout<<value<<" "<<cost<<endl;
			temp=next;
		}
	}
	for(int i=0; i<5; i++){
		cout<<count[prize[i]]<<" ";
	}
	cout<<endl<<p[n-1]-cost;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(0);
	int n;
	cin>>n;
	long long int p[n];
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	long int prize[5];
	for(int i=0; i<5; i++){
		cin>>prize[i];
	}
	for(int i=1; i<n; i++){
		p[i]+=p[i-1];
	}
	long long int cost=0;
	map<long int, long long int> count;
	for(int i=0; i<5; i++){
		count.insert(make_pair(prize[i], 0));
	}
	for(int i=0; i<n; i++){
		long long int temp=p[i]-cost;
//		long int value=*prev(upper_bound(prize, prize+n, (temp-cost)));
//		cout<<value<<endl;
//		cout<<temp<<endl;
		while(temp>=prize[0]){
			long int value=*prev(upper_bound(prize, prize+5, temp));
			long long int valuecount=temp/value;
			long long int next=temp-(valuecount*value);
			count[value]+=valuecount;
			cost+=valuecount*value;
//			cout<<value<<" "<<cost<<endl;
			temp=next;
		}
	}
	for(int i=0; i<5; i++){
		cout<<count[prize[i]]<<" ";
	}
	cout<<endl<<p[n-1]-cost;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(0);
	int n;
	cin>>n;
	long long int p[n];
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	long int prize[5];
	for(int i=0; i<5; i++){
		cin>>prize[i];
	}
	for(int i=1; i<n; i++){
		p[i]+=p[i-1];
	}
	long long int cost=0;
	map<long int, long int> count;
	for(int i=0; i<5; i++){
		count.insert(make_pair(prize[i], 0));
	}
	for(int i=0; i<n; i++){
		long long int temp=p[i]-cost;
//		long int value=*prev(upper_bound(prize, prize+n, (temp-cost)));
//		cout<<value<<endl;
//		cout<<temp<<endl;
		while(temp>=prize[0]){
			long int value=*prev(upper_bound(prize, prize+5, temp));
			long long int valuecount=temp/value;
			long long int next=temp-(valuecount*value);
			count[value]+=valuecount;
			cost+=valuecount*value;
//			cout<<value<<" "<<cost<<endl;
			temp=next;
		}
	}
	for(int i=0; i<5; i++){
		cout<<count[prize[i]]<<" ";
	}
	cout<<endl<<p[n-1]-cost;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    std::ios::sync_with_stdio(0);
	int n;
	cin>>n;
	long int p[n];
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	long int prize[5];
	for(int i=0; i<5; i++){
		cin>>prize[i];
	}
	for(int i=1; i<n; i++){
		p[i]+=p[i-1];
	}
	int cost=0;
	map<long int, long int> count;
	for(int i=0; i<5; i++){
		count.insert(make_pair(prize[i], 0));
	}
	for(int i=0; i<n; i++){
		long int temp=p[i]-cost;
//		long int value=*prev(upper_bound(prize, prize+n, (temp-cost)));
//		cout<<value<<endl;
//		cout<<temp<<endl;
		while(temp>=prize[0]){
			long int value=*prev(upper_bound(prize, prize+5, temp));
			long int valuecount=temp/value;
			long int next=temp-(valuecount*value);
			count[value]+=valuecount;
			cost+=valuecount*value;
//			cout<<value<<" "<<cost<<endl;
			temp=next;
		}
	}
	for(int i=0; i<5; i++){
		cout<<count[prize[i]]<<" ";
	}
	cout<<endl<<p[n-1]-cost;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define pii pair<int,int>
#define ppi pair<pii,int>
#define vi vector<int>
#define mp make_pair
#define minheap priority_queue<int,vector<int>,greater<int>>

int32_t main(){
FAST
 	int n,points = 0,a[5];
 	cin >> n;
 	int p[n];
 	for(int i=0;i<n;i++) {
 		cin >> p[i];
 	}
 	for(int i=0;i<5;i++) {
 		cin >> a[i];
 	}
 	int prize[5] = {};
 	for(int i=0;i<n;i++) {
 		points += p[i];
 		for(int k=0;k<5;k++) {
 		int idx = -1,mx = INT_MIN;
 		for(int j=0;j<5;j++) {
 			if(a[j] <= points && a[j] > mx) {
 				mx = a[j]; idx = j;
 			}
 		}
 		if(idx == -1) continue;
 		prize[idx] += points/a[idx];
 		points %= a[idx];}
 	}
 	for(int i=0;i<5;i++) {
 		cout << prize[i] << ' ';
 	}
 	cout <<'\n';
 	cout << points;
}


/*input
4
10 4 39 2
3 5 10 11 12
*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
using namespace std;

signed main(){
    int n;
    cin >> n;
    vi v(n);
    int points = 0;
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    int a[5],ans[5] = {};
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        points += v[i];
        bool x[5] = {};
        for(int j=0;j<5;j++){
            int mx = 0,val = 0;
            for(int k=0;k<5;k++){
                if(x[k]==false && a[k]>val){
                    mx = k;
                    val = a[k];
                }
            }
            x[mx]=true;
            ans[mx] += points/val;
            points %= val;
        }
    }
    for(int i = 0; i < 5; i++){
        cout << ans[i] << ' ';
    }
    cout << '\n' << points << '\n';
    return 0;
}


#include<iostream>
#include<utility>
#include<algorithm>
#define l long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pll pair<l,l>
#define mp make_pair

using namespace std;
class comp{
public:
bool operator()(pll a,pll b){
    return a.first>b.first;
}
};

int main(){
    l n,points=0,arr[100],x;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    pll prize[5];
    for(int i=0;i<5;i++)
    {
        cin>>x;
        prize[i].first=x;
        prize[i].second=i;
    }
    sort(prize,prize+5,comp());
    l output[5]={0};
    for(int i=0;i<n;i++)
    {
        points+=arr[i];
        for(int j=0;j<5;j++){
        l a=prize[j].first;
        l b=prize[j].second;
        output[b]+=points/a;
        points=points%a;
        }
    }
    for(int i=0;i<5;i++)
    cout<<output[i]<<" ";
    cout<<"\n"<<points<<"\n";
}


#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define vvll vector<pair<ll,ll>>
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fi first
#define se second
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define st(a) sort(a.begin(),a.end());
#define s(a) a.size()
#define rev(a) reverse(a.begin(),a.end())

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define orset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

ll gcd(ll a, ll b)
{
    if(a==0)
    return b;
    else if(b==0)
    return a;
    else if(a>b)
    return gcd(b,a%b);
    else
    return gcd(b%a,a);
}
vector <int> bfs(vector<int> g[], int N) {
vector<int>a;
queue<int>b;
bool c[N]={false};
b.push(0);
c[0]=true;
while(!b.empty())
{ int p=b.front();

a.push_back(p);
for(int i=0;i<g[p].size();i++)
{ if(c[g[p][i]]==false)
   { b.push(g[p][i]);
       c[g[p][i]]=true;}
   }

    b.pop();
}
return a;
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
    if(a.first==b.first)
     return (a.second<b.second);
    return (a.first<b.first);

}

int main()
{ int n;
cin>>n;
  ll a[n],b[5],p=0,c[5]={0};
  fr(i,0,n)
  cin>>a[i];
  fr(i,0,5)
  cin>>b[i];
  fr(i,0,n)
  { p+=a[i];
  while(p>=b[0])
  { frr(j,4,0)
  { if(b[j]<=p)
  {
      c[j]+=p/b[j];
      p%=b[j];
      break;
  }}}}
  fr(i,0,5)
  cout<<c[i]<<" ";
  cout<<endl;
  cout<<p<<endl;

}


#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define vvll vector<pair<ll,ll>>
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fi first
#define se second
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define st(a) sort(a.begin(),a.end());
#define s(a) a.size()
#define rev(a) reverse(a.begin(),a.end())

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define orset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

ll gcd(ll a, ll b)
{
    if(a==0)
    return b;
    else if(b==0)
    return a;
    else if(a>b)
    return gcd(b,a%b);
    else
    return gcd(b%a,a);
}
vector <int> bfs(vector<int> g[], int N) {
vector<int>a;
queue<int>b;
bool c[N]={false};
b.push(0);
c[0]=true;
while(!b.empty())
{ int p=b.front();

a.push_back(p);
for(int i=0;i<g[p].size();i++)
{ if(c[g[p][i]]==false)
   { b.push(g[p][i]);
       c[g[p][i]]=true;}
   }

    b.pop();
}
return a;
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
    if(a.first==b.first)
     return (a.second<b.second);
    return (a.first<b.first);

}

int main()
{ int n;
cin>>n;
  int a[n],b[5],p=0,c[5]={0};
  fr(i,0,n)
  cin>>a[i];
  fr(i,0,5)
  cin>>b[i];
  fr(i,0,n)
  { p+=a[i];
  while(p>=b[0])
  { frr(j,4,0)
  { if(b[j]<=p)
  {
      p-=b[j];
      c[j]++;
      break;
  }}}}
  fr(i,0,5)
  cout<<c[i]<<" ";
  cout<<endl;
  cout<<p<<endl;

}


#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define vvll vector<pair<ll,ll>>
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fi first
#define se second
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define st(a) sort(a.begin(),a.end());
#define s(a) a.size()
#define rev(a) reverse(a.begin(),a.end())

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define orset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

ll gcd(ll a, ll b)
{
    if(a==0)
    return b;
    else if(b==0)
    return a;
    else if(a>b)
    return gcd(b,a%b);
    else
    return gcd(b%a,a);
}
vector <int> bfs(vector<int> g[], int N) {
vector<int>a;
queue<int>b;
bool c[N]={false};
b.push(0);
c[0]=true;
while(!b.empty())
{ int p=b.front();

a.push_back(p);
for(int i=0;i<g[p].size();i++)
{ if(c[g[p][i]]==false)
   { b.push(g[p][i]);
       c[g[p][i]]=true;}
   }

    b.pop();
}
return a;
}
bool cmp(pair<int,int>a,pair<int,int>b)
{
    if(a.first==b.first)
     return (a.second<b.second);
    return (a.first<b.first);

}

int main()
{ int n;
cin>>n;
  ll a[n],b[5],p=0,c[5]={0};
  fr(i,0,n)
  cin>>a[i];
  fr(i,0,5)
  cin>>b[i];
  fr(i,0,n)
  { p+=a[i];
  while(p>=b[0])
  { frr(j,4,0)
  { if(b[j]<=p)
  {
      p-=b[j];
      c[j]++;
      break;
  }}}}
  fr(i,0,5)
  cout<<c[i]<<" ";
  cout<<endl;
  cout<<p<<endl;

}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf 1000000000000000000
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n],rem,sol=0;
    pll b[5],ans[5];
    ifr(i,0,n)cin>>a[i],ans[i].ff=0;
    ifr(i,0,5)cin>>b[i].ff,b[i].ss=i;
    sort(b,b+5);
    ifr(i,0,5)ans[i].ss=b[i].ss;
    // dbg(b,0,5);
    ifr(j,0,n){
		rem=a[j]+sol;
    	ifr(i,5,0){
    		if(b[i].ff<=rem){
    			ans[i].ff+=rem/b[i].ff;
    			rem=(rem)%b[i].ff;
    		}
    	}
    	// dbg(ans,0,5);
    	sol=rem;
    }
    sort(ans,ans+5,[] (pll x,pll y) -> bool {
    	return x.ss<y.ss;
    } );
    ifr(i,0,5)cout<<ans[i].ff<<" ";
    cout<<endl;
   	cout<<sol<<endl;
	return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf 1000000000000000000
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[51],rem,sol=0;
    pll b[5],ans[5];
    ifr(i,0,n)cin>>a[i],ans[i].ff=0;
    ifr(i,0,5)cin>>b[i].ff,b[i].ss=i;
    sort(b,b+5);
    ifr(i,0,5)ans[i].ss=b[i].ss;
    // dbg(b,0,5);
    ifr(j,0,n){
		rem=a[j]+sol;
    	ifr(i,5,0){
    		if(b[i].ff<=rem){
    			ans[i].ff+=rem/b[i].ff;
    			rem=(rem)%b[i].ff;
    		}
    	}
    	// dbg(ans,0,5);
    	sol=rem;
    }
    sort(ans,ans+5,[] (pll x,pll y) -> bool {
    	return x.ss<y.ss;
    } );
    ifr(i,0,5)cout<<ans[i].ff<<" ";
    cout<<endl;
   	cout<<sol<<endl;
	return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf 1000000000000000000
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[51],rem,sol=0;
    pll b[5],ans[5];
    ifr(i,0,n)cin>>a[i],ans[i].ff=0;
    ifr(i,0,5)cin>>b[i].ff,b[i].ss=i;
    sort(b,b+5);
    ifr(i,0,5)ans[i].ss=b[i].ss;
    // dbg(b,0,5);
    ifr(j,0,n){
		rem=a[j];
    	ifr(i,5,0){
    		if(b[i].ff<=rem){
    			ans[i].ff+=rem/b[i].ff;
    			rem=(rem)%b[i].ff;
    		}
    	}
    	// dbg(ans,0,5);
    	sol+=rem;
    }
    sort(ans,ans+5,[] (pll x,pll y) -> bool {
    	return x.ss<y.ss;
    } );
    ifr(i,0,5)cout<<ans[i].ff<<" ";
    cout<<endl;
   	cout<<sol<<endl;
	return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#ifndef ONLINE_JUDGE
    #include <lol.h>
#endif

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf 1000000000000000000
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("/home/srinivas/Desktop/cp/input.txt","r",stdin);
        //freopen("/home/srinivas/Desktop/output.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n],rem,sol=0;
    pll b[5],ans[5];
    ifr(i,0,n)cin>>a[i];
    ifr(i,0,5)cin>>b[i].ff,b[i].ss=i,ans[i].ff=0;
    sort(b,b+5);
    ifr(i,0,5)ans[i].ss=b[i].ss;
    // dbg(b,0,5);
    ifr(j,0,n){
		rem=a[j]+sol;
    	ifr(i,5,0){
    		if(b[i].ff<=rem){
    			ans[i].ff+=rem/b[i].ff;
    			rem=(rem)%b[i].ff;
    		}
    	}
    	// dbg(ans,0,5);
    	sol=rem;
    }
    sort(ans,ans+5,[] (pll x,pll y) -> bool {
    	return x.ss<y.ss;
    } );
    ifr(i,0,5)cout<<ans[i].ff<<" ";
    cout<<endl;
   	cout<<sol<<endl;
	return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair <int , int>
#define f first
#define s second

using namespace std;

int main() {
	int n;
	cin >> n;
	int p[n + 1];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &p[i]);
	}
	int v[5];
	for (int i = 0; i < 5; ++i) {
		cin >> v[i];
	}
	int cur = 0;
	int ans[5];
	memset(ans, 0, sizeof(int) * 5);
	for (int i = 0; i < n; ++i) {
		cur += p[i];
		while (cur >= v[0]) {
			int id = 0;
			while (v[id + 1] <= cur)
				id++;
			cur -= v[id];
			ans[id]++;
		}
	}
	for (int i = 0; i < 5; ++i) {
		cout << ans[i] << ' ';
	}
	cout << '\n' << cur;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair <int , int>
#define f first
#define s second

using namespace std;

int main() {
	int n;
	cin >> n;
	int p[n + 1];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &p[i]);
	}
	int v[5];
	for (int i = 0; i < 5; ++i) {
		cin >> v[i];
	}
	int cur = 0;
	int ans[5];
	memset(ans, 0, sizeof(int) * 5);
	for (int i = 0; i < n; ++i) {
		cur += p[i];
		while (cur >= v[0]) {
			int id = 0;
			while (id + 1 < 5 && v[id + 1] <= cur)
				id++;
			cur -= v[id];
			ans[id]++;
		}
	}
	for (int i = 0; i < 5; ++i) {
		cout << ans[i] << ' ';
	}
	cout << '\n' << cur;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair <int , int>
#define f first
#define s second

using namespace std;

int main() {
	ll n;
	cin >> n;
	ll p[n + 1];
	for (ll i = 0; i < n; ++i) {
		cin >> p[i];
	}
	ll v[5];
	for (ll i = 0; i < 5; ++i) {
		cin >> v[i];
	}
	ll cur = 0;
	ll ans[5];
	memset(ans, 0, sizeof(ans));
	for (ll i = 0; i < n; ++i) {
		cur += p[i];
		while (cur >= v[0]) {
			ll id = 0;
			while (id + 1 < 5 && v[id + 1] <= cur)
				id++;
			ans[id] += cur / v[id];
			cur -= v[id] * (cur / v[id]);
		}
	}
	for (ll i = 0; i < 5; ++i) {
		cout << ans[i] << ' ';
	}
	cout << '\n' << cur;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int a[20010][15],xx[20010]={0},dp[15]={0};
bool vis[20010][15]={{0}};
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
         scanf("%d",&a[i][j]);
    for(int i=0;i<k;i++)
    {
        int x,y;
         scanf("%d%d",&x,&y);
        if(!vis[x][y])
         {vis[x][y]=1;
        dp[y]++;
         }
    }

    for(int i=1;i<=n;i++)
        {
            int t=0;
            for(int j=1;j<=m;j++)
         {
            if(a[i][j]&&vis[i][j])
                t+=dp[j]-1;
            else if(a[i][j]&&!vis[i][j])
                t+=dp[j];
         }
         printf("%d ",t);
        }

    for(int i=1;i<=n;i++)

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int a[20010][15],xx[20010]={0},dp[15]={0};
bool vis[20010][15]={{0}};
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
         scanf("%d",&a[i][j]);
    for(int i=0;i<k;i++)
    {
        int x,y;
         scanf("%d%d",&x,&y);
         vis[x][y]=1;
        dp[y]++;
    }

    for(int i=1;i<=n;i++)
        {
            int t=0;
            for(int j=1;j<=m;j++)
         {
            if(a[i][j]&&vis[i][j])
                t+=dp[j]-1;
            else if(a[i][j]&&!vis[i][j])
                t+=dp[j];
         }
         printf("%d ",t);
        }

    for(int i=1;i<=n;i++)

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int a[20010][15],xx[20010]={0};
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
         scanf("%d",&a[i][j]);
    for(int i=0;i<k;i++)
    {
        int x,y;
         scanf("%d%d",&x,&y);
        for(int j=1;j<=n;j++)
            if(j!=x&&a[j][y])xx[j]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",xx[i]);
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#define MAX 20005
#define MAX2 200005
using namespace std;

int arr[MAX][12],karr[MAX2][3],n,m,k,ans[MAX];

int main()
{
    scanf("%d %d %d",&n,&m,&k);

    for (int i = 1 ; i <= n ; i++)
    {
        for (int k = 1 ; k <= m ; k++)
        {
            scanf("%d",&arr[i][k]);

        }

    }

    for (int i = 1 ; i <= k ;i++)
    {

        for (int k = 0 ; k < 2;k++)
        {
            scanf("%d",&karr[i][k]);

        }

        for (int j = 1 ; j <= n;j++)
        {

            if (j == karr[i][0])
            {

                continue;
            }
            else
            {

                if (arr[j][karr[i][1]] == 1)
                {

                    ans[j]++;
                }

            }

        }

    }

    for (int i = 1 ; i <= n ; i++)
    {
        printf("%d ",ans[i]);
    }

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#define MAX 20005
#define MAX2 200005
using namespace std;

int arr[MAX][12],n,m,k,e[MAX],c[12];

int main()
{
    scanf("%d %d %d",&n,&m,&k);

    for (int i = 1 ; i <= n ; i++)
    {
        for (int k = 1 ; k <= m ; k++)
        {
            scanf("%d",&arr[i][k]);

        }

    }
    int temp1,temp2;
    for (int i = 0 ; i < k ;i++)
    {
        scanf("%d %d",&temp1,&temp2);

        e[temp1]--;
        c[temp2]++;

    }

     for (int i = 1 ; i <= n ; i++)
    {
        for (int k = 1 ; k <= m ; k++)
        {
            if (arr[i][k])
            {
                e[i] += c[k];

            }

        }

    }

    for (int i = 1 ; i <= n;i++)
    {
        printf("%d ",e[i]);
    }

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#define MAX 20005
#define MAX2 200005
using namespace std;

int arr[MAX][12],karr[MAX2][3],n,m,k,ans[MAX];

int main()
{
    scanf("%d %d %d",&n,&m,&k);

    for (int i = 1 ; i <= n ; i++)
    {
        for (int k = 1 ; k <= m ; k++)
        {
            scanf("%d",&arr[i][k]);

        }

    }

    for (int i = 1 ; i <= k ;i++)
    {

        for (int k = 0 ; k < 2;k++)
        {
            scanf("%d",&karr[i][k]);

        }

    }

    for (int i = 1 ; i <= k ;i++)
    {

        for (int j = 1 ; j <= n;j++)
        {

            if (j == karr[i][0])
            {

                continue;
            }
            else
            {

                if (arr[j][karr[i][1]] == 1)
                {

                    ans[j]++;
                }

            }

        }

    }

    for (int i = 1 ; i <= n ; i++)
    {
        printf("%d ",ans[i]);
    }

    return 0;
}


#include<stdio.h>

int main()
{
   int n,m,k;
   while(scanf("%d %d %d",&n,&m,&k)==3)
   {
      int arr[n+5][m+5];
      int num[20005]={0};
      for(int i=1;i<=n;i++)
      {
         for(int j=1;j<=m;j++)
            scanf("%d",&arr[i][j]);
      }
      for(int i=1;i<=k;i++)
      {
         int x,y;
         scanf("%d %d",&x,&y);
         for(int j=1;j<=n;j++)
         {
            if(arr[j][y] && j!=x)
            {
               num[j]++;
            }
         }
      }
      for(int i=1;i<=n;i++)
         printf("%d ",num[i]);
      printf("\n");
   }
   return 0;
}


#include<stdio.h>

int main()
{
   int n,m,k;
   while(scanf("%d %d %d",&n,&m,&k)==3)
   {
      int arr[n+5][m+5];
      int num[n+5]={0};
      for(int i=1;i<=n;i++)
      {
         for(int j=1;j<=m;j++)
            scanf("%d",&arr[i][j]);
      }
      for(int i=1;i<=k;i++)
      {
         int x,y;
         scanf("%d %d",&x,&y);
         for(int j=1;j<=n;j++)
         {
            if(arr[j][y] && j!=x)
            {
               num[j]++;
            }
         }
      }
      for(int i=1;i<=n;i++)
         printf("%d ",num[i]);
      printf("\n");
   }
   return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k,i,j;
    cin>>n>>m>>k;
    int a[n][m],b[k][2],c[n];
    vector <int> v[m];
    for(i=0;i<n;i++)
    {
             c[i]=0;
             for(j=0;j<m;j++)
             {
                scanf("%d",&a[i][j]);
                if(a[i][j]==1)
                v[j].push_back(i);
             }
    }
    for(i=0;i<k;i++)
    {
           scanf("%d%d",&b[i][0],&b[i][1]);
           for(j=0;j<v[b[i][1]-1].size();j++)
           {
                 if(v[b[i][1]-1][j]!=b[i][0])
                 c[v[b[i][1]-1][j]]++;
           }
    }
    for(i=0;i<n;i++)
    printf("%d ",c[i]);
    printf("\n");

    return 0;
}


#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
    int n,m,k,i,j,z,y;
    cin>>n>>m>>k;
    vector <int> v[m+1],v1[m+1];
    int a[n+1][m+1],b[n+1];
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
    {
          for(j=0;j<m;j++)
          {
                 cin>>z;
                 if(z==1)
                 {
                     v[j+1].push_back(i+1);
                 }
          }
    }
    for(i=0;i<k;i++)
    {
          cin>>y>>z;
          v1[z].push_back(y);
          a[y][z]++;
    }
    for(i=1;i<=m;i++)
    {
         for(j=0;j<v[i].size();j++)
         {
                 b[v[i][j]]+=(v1[i].size()-a[v[i][j]][i]);
         }
     }
     for(i=1;i<=n;i++)
     {
         cout<<b[i]<<" ";
     }
     //system("pause");
     return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k,i,j;
    cin>>n>>m>>k;
    int a[n][m],b[k][2],c[n];
    vector <int> v[m];
    for(i=0;i<n;i++)
    {
             c[i]=0;
             for(j=0;j<m;j++)
             {
                scanf("%d",&a[i][j]);
                if(a[i][j]==1)
                v[j].push_back(i);
             }
    }
    for(i=0;i<k;i++)
    {
           scanf("%d%d",&b[i][0],&b[i][1]);
           for(j=0;j<v[b[i][1]-1].size();j++)
           {
                 if(v[b[i][1]-1][j]!=b[i][0]-1)
                 {
                 c[v[b[i][1]-1][j]]++;
                 //cout<<b[i][0]<<" "<<b[i][1]<<endl;
                 }
           }
    }
    for(i=0;i<n;i++)
    printf("%d ",c[i]);
    printf("\n");

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,k,i,j;
    cin>>n>>m>>k;
    int a[n][m],b[k][2],c[n];
    vector <int> v[m];
    for(i=0;i<n;i++)
    {
             c[i]=0;
             for(j=0;j<m;j++)
             {
                cin>>a[i][j];
                if(a[i][j]==1)
                v[j].push_back(i);
             }
    }
    for(i=0;i<k;i++)
    {
           cin>>b[i][0]>>b[i][1];
           for(j=0;j<v[b[i][1]-1].size();j++)
           {
                 if(v[b[i][1]-1][j]!=b[i][0]-1)
                 {
                 c[v[b[i][1]-1][j]]++;
                 //cout<<b[i][0]<<" "<<b[i][1]<<endl;
                 }
           }
    }
    for(i=0;i<n;i++)
    printf("%d ",c[i]);
    printf("\n");

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int lo=-2e9;
int hi=2e9;

int main()
{
    int n,m,k,b[100000],a[40000][10];

    cin>>n>>m>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];

    while(k--)
    {
        int x,y;

        cin>>x>>y;

        for(int i=0;i<n;i++)
        {
            if(i!=x-1)
            {
                if(a[i][y-1]!=0)
                {
                    b[i]++;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<b[i]<<" ";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int lo=-2e9;
int hi=2e9;

int main()
{
    int n,m,k,M[15],N[20000],a[20000][15];

    cin>>n>>m>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];

    int x,y;
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        x--;
        y--;
        N[x]--;
        M[y]++;
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i][j]!=0){
            N[i]+=M[j];
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<N[i]<<" ";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int lo=-2e9;
int hi=2e9;

int main()
{
    int n,m,k,b[100000];

    cin>>n>>m>>k;

    int a[n][m];

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];

    while(k--)
    {
        int x,y;

        cin>>x>>y;

        for(int i=0;i<n;i++)
        {
            if(i!=x-1)
            {
                if(a[i][y-1]!=0)
                {
                    b[i]++;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<b[i]<<" ";

    return 0;
}


#include <iostream>
#include <fstream>
using namespace std;

fstream fin("B.in");

int N, M ,K;
bool m[2 * 10005][12];
int cnt[2 * 10005];

int main() {
    cin >> N >> M >> K;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            cin >> m[i][j];
        }
    }
    int x, chat;
    for (int i = 0; i < K; ++i) {
        cin >> x >> chat;
        for (int j = 1; j <= N; ++j) {
            if (m[j][chat] && j != x)
                ++cnt[j];
        }
    }
    for (int i = 1; i <= N; ++i)
        cout << cnt[i] << ' ';
    fin.close();
    return 0;
}


#include <iostream>
#include <fstream>
using namespace std;

fstream fin("B.in");

int N, M ,K;
bool m[2 * 10005][12];
int sent[20005], received[15];
int cnt[2 * 10005];

int main() {
    cin >> N >> M >> K;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            cin >> m[i][j];
        }
    }
    int x, chat;
    for (int i = 0; i < K; ++i) {
        cin >> x >> chat;
        ++sent[x];
        ++received[chat];
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j)
            if (m[i][j])
                cnt[i] += received[j];
    }
    for (int i = 1; i <= N; ++i) {
        cout << cnt[i] - sent[i] << ' ';
    }
    fin.close();
    return 0;
}


#include <iostream>
#include <fstream>
using namespace std;

fstream fin("B.in");

int N, M ,K;
bool m[2 * 10005][12];
int sent[10005], received[15];
int cnt[2 * 10005];

int main() {
    cin >> N >> M >> K;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            cin >> m[i][j];
        }
    }
    int x, chat;
    for (int i = 0; i < K; ++i) {
        cin >> x >> chat;
        ++sent[x];
        ++received[chat];
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j)
            if (m[i][j])
                cnt[i] += received[j];
    }
    for (int i = 1; i <= N; ++i) {
        cout << cnt[i] - sent[i] << ' ';
    }
    fin.close();
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=20000+10;
const int maxm=10+10;
int adj[maxn][maxm];
int x[maxn*10],y[maxn*10];
int sum[maxm];
int h[maxn][maxm];
int n,m,k;
int main()
{
    //freopen("G:\\in.txt","r",stdin);
    while(cin>>n>>m>>k)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cin>>adj[i][j];
        }
        for(int i=1;i<=k;i++)
        {
            cin>>x[i]>>y[i];
            sum[y[i]]++;
           h[x[i]][y[i]]++;
        }
       // for(int i=1;i<=m;i++)
            //cout<<sum[i]<<endl;
            int f=1;
        for(int i=1;i<=n;i++)
        {
            int s=0;
            for(int j=1;j<=m;j++)
            {
                if(adj[i][j])
                {
                    s+=sum[j];
                    s-=h[i][j];
                }

            }
            if(f)
            cout<<s;
            else
            cout<<" "<<s;
            f=0;
        }
        cout<<endl;
    }
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=20000+10;
const int maxm=10+10;
int adj[maxn][maxm];
int x[maxn],y[maxn];
int sum[maxm];
int h[maxn][maxm];
int n,m,k;
int main()
{
    freopen("G:\\in.txt","r",stdin);
    while(cin>>n>>m>>k)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cin>>adj[i][j];
        }
        for(int i=1;i<=k;i++)
        {
            cin>>x[i]>>y[i];
            sum[y[i]]++;
           h[x[i]][y[i]]++;
        }
       // for(int i=1;i<=m;i++)
            //cout<<sum[i]<<endl;
        for(int i=1;i<=n;i++)
        {
            int s=0;
            for(int j=1;j<=m;j++)
            {
                if(adj[i][j])
                {
                    s+=sum[j];
                    s-=h[i][j];
                }

            }
            cout<<s<<" ";
        }
        cout<<endl;
    }
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=20000+10;
const int maxm=10+10;
int adj[maxn][maxm];
int x[maxn],y[maxn];
int sum[maxm];
int h[maxn][maxm];
int n,m,k;
int main()
{
    //freopen("G:\\in.txt","r",stdin);
    while(cin>>n>>m>>k)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cin>>adj[i][j];
        }
        for(int i=1;i<=k;i++)
        {
            cin>>x[i]>>y[i];
            sum[y[i]]++;
           h[x[i]][y[i]]++;
        }
       // for(int i=1;i<=m;i++)
            //cout<<sum[i]<<endl;
            int f=1;
        for(int i=1;i<=n;i++)
        {
            int s=0;
            for(int j=1;j<=m;j++)
            {
                if(adj[i][j])
                {
                    s+=sum[j];
                    s-=h[i][j];
                }

            }
            if(f)
            cout<<s;
            else
            cout<<" "<<s;
            f=0;
        }
        cout<<endl;
    }
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=2e4+5;
vint v[maxn];
int n,m,k,res[maxn],chat[15],send[maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; i++)
        for(int j=1 ; j<=m ; j++){
            int x;cin>>x;
            if(x==1)
                v[i].pb(j);
        }
    for(int i=1 ; i<=k ; i++){
        int x,y;cin>>x>>y;
        chat[y]++;
        send[x]++;
    }
    for(int i=1 ; i<=n ; i++){
        int ans=0;
        for(int j=0 ; j<(int)v[i].size() ; j++)
            ans+=chat[v[i][j]];
        ans-=send[i];
        cout<<ans<<' ';
    }
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=2e4+5;
vint v[maxn];
int send[maxn],chat[15];

int main(){
    ios_base::sync_with_stdio(false);
    int n,m,q;cin>>n>>m>>q;
    for(int i=1 ; i<=n ; i++){
        for(int j=1 ; j<=m ; j++){
            int x;cin>>x;
            if(x==1)
                v[i].pb(j);
        }
    }
    for(int i=1 ; i<=q ; i++){
        int u1,u2;
        cin>>u1>>u2;
        send[u1]++;
        chat[u2]++;
    }
    for(int i=1 ; i<=n ; i++){
        int ans=0;
        for(int j=0 ; j<v[i].size() ; j++){
            ans+=chat[v[i][j]];
        }
        ans-=send[i];
        cout<<ans<<' ';
    }
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=2e4+5;
vint chat[15];
int n,m,k,res[maxn];
void go(int mol){
    for(int i=0 ; i<(int)chat[mol].size() ; i++)
        res[chat[mol][i]]++;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1 ; i<=n ; i++)
        for(int j=1 ; j<=m ; j++){
            int x;cin>>x;
            if(x==1)
                chat[j].pb(i);
        }
    for(int i=1 ; i<=k ; i++){
        int x,y;cin>>x>>y;
        go(y);
        res[x]--;
    }
    for(int i=1 ; i<=n ; i++)
        cout<<res[i]<<' ';
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

int n,m,k,a[100000][20],ans[100000];

bool comp(int a,int b){
    return(a<b);
}

bool isc(char a){
    return(49<=a-'0'&&74>=a-'0');
}

bool isa(char a){
    return(0<=a-'0'&&9>=a-'0');
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=0;i<k;i++){
        int tmp,notplus;
        scanf("%d %d", &notplus,&tmp);
        tmp--;
        for(int j=0;j<n;j++){
            if(a[j][tmp]==1&&j!=notplus-1)
                ans[j]++;
              //  cout<<ans[j]<<' ';
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<' ';
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

int n,m,k,a[100000][20],ans[100000];

bool comp(int a,int b){
    return(a<b);
}

bool isc(char a){
    return(49<=a-'0'&&74>=a-'0');
}

bool isa(char a){
    return(0<=a-'0'&&9>=a-'0');
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int tmp,notplus;
    for(int i=0;i<k;i++){
        scanf("%d %d", &notplus,&tmp);
        tmp--;
        for(int j=0;j<n;j++){
            if(a[j][tmp]==1&&j!=notplus-1)
                ans[j]++;
              //  cout<<ans[j]<<' ';
        }
    }
    for(int i=0;i<n;i++){
        printf("%d ",ans[i]<<' ');
    }
    return 0;
}