Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.

Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.

The sweepstake has the following prizes (the prizes are sorted by increasing of their cost): 

  * a mug (costs a points), 
  * a towel (costs b points), 
  * a bag (costs c points), 
  * a bicycle (costs d points), 
  * a car (costs e points). 



Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Output

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
3 10 4
2 4 10 15 20


Output

1 1 1 0 0 
1


Input

4
10 4 39 2
3 5 10 11 12


Output

3 0 1 0 3 
0

Note

In the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import bisect
n = int(input())
a = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
b = [0, 0, 0, 0, 0]
s = 0
for i in a:
	s += i
	k = bisect.bisect_right(p, s)
	while k != 0:
		if k == 5 or p[k] > s:
			k -= 1
		b[k] += s // p[k]
		s %= p[k]
		k = bisect.bisect_right(p, s)
print(' '.join(list(map(str, b))))
print(s)


n = int(input())
L = []
p = [0, 0, 0, 0, 0]
L = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
s = 0
for i in range(n):
	s += L[i]
	if s >= e:
		p[4] += s // e
		s -= e * (s // e)
	if s >= d:
		p[3] += s // d
		s -= d * (s // d)
	if s >= c:
		p[2] += s // c
		s -= c * (s // c)
	if s >= b:
		p[1] += s // b
		s -= b * (s // b)
	if s >= a:
		p[0] += s // a
		s -= a * (s // a)
print(*p)
print(s)


input()
pts = [int(x) for x in input().split()]
przs = list(map(int, input().split()))
(cur, ans) = (0, [0] * 5)
for j in pts:
	cur += j
	i = 4
	while i >= 0:
		ans[i] += cur // przs[i]
		cur -= przs[i] * (cur // przs[i])
		i -= 1
print(*ans)
print(cur)


input()
v = [int(i) for i in input().split(' ')]
w = [int(i) for i in input().split(' ')][::-1]
r = [0, 0, 0, 0, 0]
s = 0
for a in v:
	s += a
	for (i, b) in enumerate(w):
		r[i] += s // b
		s -= s // b * b
print(' '.join((str(i) for i in r[::-1])))
print(s)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
(a, b, c, d, e) = map(int, input().strip().split(' '))
l2 = [a, b, c, d, e]
ar = [0] * 5
s = 0
for j in range(n):
	s += lst[j]
	for k1 in range(5):
		m = 0
		ind = 0
		for k in range(5):
			if l2[k] > m and l2[k] <= s:
				m = l2[k]
				ind = k
		if m > 0:
			ar[ind] += s // m
			s -= l2[ind] * (s // m)
		if s < min(l2):
			break
for j in range(5):
	print(ar[j], end=' ')
print()
print(s)


n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
s1 = [0] * 5
s2 = 0
for i in p:
	s2 += i
	while s2 >= a[0]:
		prize = 0
		for (i, el) in enumerate(a):
			if el <= s2:
				prize = i
			else:
				break
		s1[prize] += s2 // a[prize]
		s2 %= a[prize]
print(*s1)
print(s2)


from sys import stdin, stderr

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(ns, vs):
	vs.reverse()
	freqs = {}
	cur = 0
	for v in vs:
		freqs[v] = 0
	for p in ns:
		cur += p
		for v in vs:
			if v <= cur:
				b = cur // v
				freqs[v] += b
				cur -= b * v
	out = []
	vs.reverse()
	for v in vs:
		out.append(freqs[v])
	return (out, cur)

def run():
	(n,) = readInts()
	ns = readInts()
	vs = list(readInts())
	(buys, remain) = solve(ns, vs)
	buys = map(str, buys)
	buys = ' '.join(buys)
	print(buys)
	print(remain)
run()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
prizes = array()
left = 0
count = [0] * 5
for i in a:
	left += i
	ind = bisect_right(prizes, left) - 1
	while ind >= 0:
		here = left // prizes[ind]
		left -= prizes[ind] * here
		count[ind] += here
		ind = bisect_right(prizes, left) - 1
print(*count)
print(left)


n = int(input())
arr = [int(x) for x in input().split()]
cost = [int(x) for x in input().split()]
cost.reverse()
bought = [0 for i in range(5)]
mon = 0
for i in arr:
	mon += i
	for j in range(5):
		if mon >= cost[j]:
			num = mon // cost[j]
			bought[4 - j] += num
			mon -= cost[j] * num
for i in bought:
	print(i, end=' ')
print(' ')
print(mon)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(1):
	n = nmbr()
	a = lst()
	obj = lst()
	pts = 0
	ans = [0] * 5
	for v in a:
		pts += v
		taken = 1
		while pts > 0 and taken:
			taken = mx = 0
			for i in range(5):
				if pts >= obj[i]:
					taken = 1
					if mx == 0 or obj[mx] < obj[i]:
						mx = i
			if taken:
				used = pts // obj[mx]
				pts -= used * obj[mx]
				ans[mx] += used
	print(*ans)
	print(pts)


import bisect
n = int(input())
a = list(map(int, input().split()))
s = 0
b = list(map(int, input().split()))
ans = [0] * 5
for j in a:
	s += j
	for i in range(4, -1, -1):
		if s >= b[i]:
			temp = s // b[i]
			ans[i] += temp
			s = s % b[i]
print(*ans)
print(s)


n = int(input())
(sum, a, b, c, d, e) = (0, 0, 0, 0, 0, 0)
numbers = [int(x) for x in input().split(' ')]
prizes = [int(x) for x in input().split(' ')]
prizes.sort()
for num in numbers:
	sum += num
	if sum >= prizes[4]:
		e += int(sum / prizes[4])
		sum = sum % prizes[4]
	if sum >= prizes[3]:
		d += int(sum / prizes[3])
		sum = sum % prizes[3]
	if sum >= prizes[2]:
		c += int(sum / prizes[2])
		sum = sum % prizes[2]
	if sum >= prizes[1]:
		b += int(sum / prizes[1])
		sum = sum % prizes[1]
	if sum >= prizes[0]:
		a += int(sum / prizes[0])
		sum = sum % prizes[0]
print(f'{a} {b} {c} {d} {e}')
print(sum)


n = int(input())
p = [int(k) for k in input().split()]
prices = [int(k) for k in input().split()]
prices.reverse()
purchased = [0] * 5
s = 0
for i in p:
	s += i
	for j in range(5):
		purchased[j] += int(s / prices[j])
		s -= prices[j] * int(s / prices[j])
g = ''
for i in purchased:
	g = str(i) + ' ' + g
print(g)
print(s)


def most_expensive_prize(prize_cost_list, current_sum):
	for c in prize_cost_list[::-1]:
		if c <= current_sum:
			return c
	return 0

def prize_count_list(v, prize_cost_list):
	prize_count_dict = {c: 0 for c in prize_cost_list}
	current_sum = 0
	for c in v:
		current_sum += c
		while current_sum >= prize_cost_list[0]:
			t = most_expensive_prize(prize_cost_list, current_sum)
			count_of_prize = current_sum // t
			current_sum -= t * count_of_prize
			prize_count_dict[t] += count_of_prize
	return (prize_count_dict.values(), current_sum)
input()
v = [int(c) for c in input().split()]
prize_cost_list = [int(c) for c in input().split()]
(lst, current_sum) = prize_count_list(v, prize_cost_list)
print(*lst)
print(current_sum)


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[n] = get()
	a = get()
	b = get()
	c = [0] * 5
	s = 0
	for i in range(n):
		s += a[i]
		k = 2
		while k != -1:
			k = -1
			for j in range(5):
				if s >= b[j]:
					k = j
			if k != -1:
				c[k] += s // b[k]
				s = s % b[k]
	for i in c:
		print(i, end=' ')
	print(s)
	if mode == 'file':
		f.close()
main()


def main():
	input()
	m = map(int, input().split())
	gifts = list(map(int, input().split())) + [10 ** 12]
	(s, res) = (0, [0] * 5)
	for p in m:
		s += p
		while s >= gifts[0]:
			for (g, p) in enumerate(gifts):
				if s < p:
					g -= 1
					p = gifts[g]
					x = s // p
					res[g] += x
					s -= x * p
					break
	print(*res)
	print(s)
main()


n = int(input())
arr = [int(i) for i in input().split()]
prizes = [int(i) for i in input().split()]
prizes_got = [0] * 5
points_left = 0
for i in range(n):
	points_left += arr[i]
	for j in range(len(prizes) - 1, -1, -1):
		if points_left >= prizes[j]:
			prizes_got[j] += int(points_left / prizes[j])
			points_left = points_left % prizes[j]
print(*prizes_got)
print(points_left)


n = int(input())
(*pi,) = map(int, input().split())
(*prize,) = map(int, input().split())
total = [0, 0, 0, 0, 0]
temp = 0
for i in pi:
	temp += i
	if temp >= prize[-1]:
		total[4] += temp // prize[-1]
		temp -= prize[-1] * (temp // prize[-1])
	if temp >= prize[-2]:
		total[3] += temp // prize[-2]
		temp -= prize[-2] * (temp // prize[-2])
	if temp >= prize[-3]:
		total[2] += temp // prize[-3]
		temp -= prize[-3] * (temp // prize[-3])
	if temp >= prize[-4]:
		total[1] += temp // prize[-4]
		temp -= prize[-4] * (temp // prize[-4])
	if temp >= prize[-5]:
		total[0] += temp // prize[-5]
		temp -= prize[-5] * (temp // prize[-5])
print(*total)
print(temp)


n = int(input())
p = list(map(int, input().split()))
pz = list(map(int, input().split()))
res = [0] * 5
cur_pz = 0
for i in p:
	cur_pz += i
	for j in range(len(pz) - 1, -1, -1):
		res[j] += cur_pz // pz[j]
		cur_pz = cur_pz % pz[j]
print(' '.join((str(i) for i in res)))
print(cur_pz)


L = lambda : list(map(int, input().split()))
L()
P = L()
X = L()
C = [0] * 5
s = 0
for p in P:
	s += p
	for i in reversed(range(5)):
		(k, s) = divmod(s, X[i])
		C[i] += k
print(*C)
print(s)


n = int(input())
p = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
points = 0
(a1, b1, c1, d1, e1) = (0, 0, 0, 0, 0)
for i in range(n):
	points += p[i]
	e1 += points // e
	points -= points // e * e
	d1 += points // d
	points -= points // d * d
	c1 += points // c
	points -= points // c * c
	b1 += points // b
	points -= points // b * b
	a1 += points // a
	points -= points // a * a
print(a1, b1, c1, d1, e1)
print(points)


siz = int(input())
(fef, cuc) = (0, [0] * 5)
fuk = list(map(int, input().split()))
shit = list(map(int, input().split()))
for sus in fuk:
	fef += sus
	for piss in range(4, -1, -1):
		cuc[piss] += fef // shit[piss]
		fef -= fef // shit[piss] * shit[piss]
print(*cuc)
print(fef)


n = int(input())
prize_points = list(map(int, input().split()))
price = list(map(int, input().split()))
points_bal = 0
items = [0] * 5
for (t, point_rec) in enumerate(prize_points):
	points_bal += point_rec
	for i in range(4, -1, -1):
		num_items = points_bal // price[i]
		points_bal -= num_items * price[i]
		items[i] += num_items
for i in items:
	print(i, end=' ')
print('')
print(points_bal)


chocolate_bars = int(input())
wrappers = list(map(int, input().strip().split()))
prizes = sorted(map(int, input().strip().split()), reverse=True)
swag = [0] * 5
points = 0
for wrapper in wrappers:
	points += wrapper
	for (i, prize) in enumerate(prizes):
		if points >= prize:
			bought = points // prize
			swag[i] += bought
			points -= prize * bought
print(*swag[::-1])
print(points)


import sys
input = sys.stdin.readline
import bisect
n = int(input())
p = list(map(int, input().split()))
prizes = list(map(int, input().split()))
prizes_cnt = [0] * 5
curr_points = 0
for el in p:
	curr_points += el
	idx = bisect.bisect_right(prizes, curr_points)
	while idx:
		if idx:
			prizes_cnt[idx - 1] += curr_points // prizes[idx - 1]
			curr_points = curr_points % prizes[idx - 1]
		else:
			break
		idx = bisect.bisect_right(prizes, curr_points)
print(*prizes_cnt)
print(curr_points)


n = int(input())
l = list(map(int, input().split()))
p = list(map(int, input().split()))
su = 0
res = [0] * 5
for i in l:
	su += i
	while su >= p[0]:
		lol = 0
		jj = 0
		for j in range(5):
			if p[j] > su:
				lol = 1
				if j > 0:
					res[j - 1] += su // p[j - 1]
					su = su % p[j - 1]
				break
			jj = j
		if lol == 0 and jj != 0:
			res[-1] += su // p[-1]
			su = su % p[-1]
while 1:
	if su < p[0]:
		break
	for i in range(5):
		if p[i] > su:
			res[i - 1] += su // p[i - 1]
			su = su % p[i - 1]
print(*res)
print(su)


__author__ = 'Utena'
n = int(input())
l = list(map(int, input().split()))
p = list(map(int, input().split()))[::-1]
q = len(p)
s = [0] * 5
v = 0
for i in range(n):
	v += l[i]
	for j in range(q):
		if p[j] <= v:
			s[4 - j] += int(v / p[j])
			v = v % p[j]
print(' '.join(map(str, s)))
print(v)


import bisect
n = int(input())
l = list(map(int, input().split()))
c = list(map(int, input().split()))
count = 0
f = [0] * 5
for i in range(n):
	count = count + l[i]
	while count >= c[0]:
		j = bisect.bisect(c, count) - 1
		p = count // c[j]
		f[j] = f[j] + p
		count = count - count // c[j] * c[j]
for i in range(5):
	print(f[i], end=' ')
print()
print(count)


chocolates = int(input())
points = list(map(int, input().split()))
costs = list(reversed(list(map(int, input().split()))))
lst = [0] * 5
present = 0
for i in points:
	present += i
	for j in range(5):
		if present // costs[j] != 0:
			lst[j] += present // costs[j]
			present = present % costs[j]
			if present == 0:
				break
print(*reversed(lst))
print(present)


n = int(input())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
p.reverse()
q = [0] * 5
s = 0
for i in range(n):
	s += t[i]
	j = 0
	while j < 5:
		if s < p[j]:
			j += 1
		else:
			k = s // p[j]
			s -= k * p[j]
			q[j] += k
q.reverse()
print(' '.join((str(i) for i in q)))
print(s)


n = int(input())
points = [int(i) for i in input().split()]
costs = [int(i) for i in input().split()]
prizes = [0 for i in range(5)]
sum = 0
for p in points:
	sum += p
	while sum >= costs[0]:
		if sum >= costs[4]:
			bigprizes = sum // costs[4]
			prizes[4] += bigprizes
			sum -= costs[4] * bigprizes
		elif sum >= costs[3]:
			prizes[3] += 1
			sum -= costs[3]
		elif sum >= costs[2]:
			prizes[2] += 1
			sum -= costs[2]
		elif sum >= costs[1]:
			prizes[1] += 1
			sum -= costs[1]
		elif sum >= costs[0]:
			prizes[0] += 1
			sum -= costs[0]
for i in prizes:
	print(i, end=' ')
print()
print(sum)


n = int(input())
P = list(map(int, input().split()))
L = list(map(int, input().split()))
Taken = [0] * 5
x = 0
for i in range(n):
	x += P[i]
	ind = 4
	for j in range(5):
		if L[j] > x:
			ind = j - 1
			break
	if ind == -1:
		continue
	else:
		for j in range(ind, -1, -1):
			Taken[j] += x // L[j]
			x = x - x // L[j] * L[j]
print(Taken[0], Taken[1], Taken[2], Taken[3], Taken[4])
print(x)


from sys import stdin
import bisect
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
cost = list(map(int, stdin.readline().split()))
count = [0] * 5
i = 0
total = 0
while i < n:
	total += arr[i]
	while True:
		index = bisect.bisect(cost, total) - 1
		if index < 0:
			break
		count[index] += total // cost[index]
		total = total % cost[index]
	i += 1
print(*count)
print(total)


n = int(input())
l = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
(a1, b1, c1, d1, e1) = (0, 0, 0, 0, 0)
l.append(0)
for j in range(n):
	if l[j] >= e:
		e1 += l[j] // e
		l[j] -= e * (l[j] // e)
	if l[j] >= d:
		d1 += l[j] // d
		l[j] -= d * (l[j] // d)
	if l[j] >= c:
		c1 += l[j] // c
		l[j] -= c * (l[j] // c)
	if l[j] >= b:
		b1 += l[j] // b
		l[j] -= b * (l[j] // b)
	if l[j] >= a:
		a1 += l[j] // a
		l[j] -= a * (l[j] // a)
	l[j + 1] = l[j + 1] + l[j]
print(a1, b1, c1, d1, e1)
print(l[n])


n = int(input())
s = input()
s1 = s.split()
arr1 = []
for i in range(n):
	arr1.append(int(s1[i]))
arr2 = []
s = input()
s1 = s.split()
for i in range(5):
	arr2.append(int(s1[i]))
sum = 0
counts = []
for i in range(5):
	counts.append(0)
for i in range(n):
	sum += arr1[i]
	while sum >= arr2[0]:
		if sum >= arr2[4]:
			counts[4] += int(sum / arr2[4])
			sum %= arr2[4]
		for j in range(4):
			if sum >= arr2[j] and sum < arr2[j + 1]:
				sum -= arr2[j]
				counts[j] += 1
s = ''
for i in range(5):
	s += str(counts[i]) + ' '
print(s)
print(sum)


from sys import stdin
from bisect import bisect_right as bl
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
sum1 = 0
r = [0] * 5
for i in range(n):
	sum1 += a[i]
	while sum1 >= b[0]:
		m = bl(b, sum1)
		v = sum1
		nm = v // b[m - 1]
		mod = v % b[m - 1]
		r[m - 1] += nm
		sum1 = mod
print(*r)
print(sum1)


n = int(input())
p = list(map(int, input().split()))
pri = list(map(int, input().split()))
c = [0] * 5
s = 0
for i in range(n):
	s += p[i]
	for j in range(4, -1, -1):
		d = s // pri[j]
		c[j] += d
		s -= d * pri[j]
for i in range(5):
	print(c[i], end=' ')
print('')
print(s)


n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
freq = [0] * 5
points = 0
for i in a1:
	points += i
	for i in range(4, -1, -1):
		freq[i] += points // a2[i]
		points = points % a2[i]
print(*freq)
print(points)


n = int(input())
ps = map(int, input().split())
(a, b, c, d, e) = map(int, input().split())
prize_amount = [[a, 0], [b, 0], [c, 0], [d, 0], [e, 0]]
prize_amount.reverse()
x = 0
for p in ps:
	x += p
	for i in range(len(prize_amount)):
		prize_amount[i] = [prize_amount[i][0], prize_amount[i][1] + x // prize_amount[i][0]]
		x %= prize_amount[i][0]
prize_amount.reverse()
print(' '.join(map(lambda x: str(x[1]), prize_amount)))
print(x)


n = int(input())
p = list(map(int, input().split()))
cost = list(map(int, input().split()))
res = [0 for i in range(5)]
x = 0
for i in range(n):
	x += p[i]
	for j in reversed(range(5)):
		if cost[j] <= x:
			t = x // cost[j]
			res[j] += t
			x = x % cost[j]
for r in res:
	print(r, end=' ')
print('\n' + str(x))


n = int(input())
ans = [0] * 5
l = list(map(int, input().split()))
v = list(map(int, input().split()))
v.reverse()
cnt = 0
for t in l:
	cnt += t
	for i in range(len(v)):
		if cnt >= v[i]:
			m = cnt // v[i]
			cnt -= m * v[i]
			ans[i] += m
ans.reverse()
print(*ans)
print(cnt)


(N, SUM) = (int(input()), 0)
X = list(map(int, input().split()))
(Temp, Prize) = ([0] * 5, list(map(int, input().split())))
for i in X:
	SUM = SUM + i
	for i in range(4, -1, -1):
		if SUM >= Prize[i]:
			Num = SUM // Prize[i]
			(SUM, Temp[i]) = (SUM - Prize[i] * Num, Temp[i] + Num)
print(*Temp)
print(SUM)


n = int(input())
p = map(int, input().split())
cost = list(map(int, input().split()))
left_points = 0
ans = [0 for i in range(len(cost))]
for points in p:
	left_points += points
	for i in range(len(cost) - 1, -1, -1):
		buy_cnt = left_points // cost[i]
		ans[i] += buy_cnt
		left_points -= buy_cnt * cost[i]
print(' '.join(list(map(str, ans))))
print(left_points)


n = int(input())
arr = list(map(int, input().split()))
val = list(map(int, input().split()))
count = [0] * 5
curr = 0
for i in arr:
	curr += i
	for j in range(4, -1, -1):
		count[j] += curr // val[j]
		curr = curr % val[j]
for i in count:
	print(i, end=' ')
print()
print(curr)


n = int(input())
b = 0
a = list(map(int, input().split(' ')))
p = list(map(int, input().split(' ')))
f = [0] * len(p)
for i in range(len(a)):
	b += a[i]
	for i in range(len(p) - 1, -1, -1):
		f[i] += b // p[i]
		b -= b // p[i] * p[i]
print(*f)
print(b)


n = int(input())
point = [int(p) for p in input().split()]
cost = [int(c) for c in input().split()]
s = 0
t = [0] * 5
for i in point:
	s += i
	for j in range(4, -1, -1):
		t[j] += s // cost[j]
		s %= cost[j]
print(*t)
print(s)


n = int(input())
p = list(map(int, input().split()))
cost = list(map(int, input().split()))
ls = [0] * 5
curr = 0
for i in p:
	curr += i
	for j in range(4, -1, -1):
		if cost[j] <= curr:
			curr -= cost[j]
			ls[j] += 1
			while curr >= cost[j]:
				ls[j] += curr // cost[j]
				curr -= cost[j] * (curr // cost[j])
print(*ls)
print(curr)


n = int(input())
(*p,) = map(int, input().split())
(*a,) = map(int, input().split())
b = [0] * 5
s = 0
for i in p:
	s += i
	for j in range(4, -1, -1):
		b[j] += s // a[j]
		s %= a[j]
print(*b, s)


import sys
input = sys.stdin.readline
for _ in range(1):
	n = int(input())
	ans = [0 for i in range(5)]
	arr = [int(x) for x in input().split()]
	temp = [int(x) for x in input().split()]
	curr = 0
	for i in arr:
		curr += i
		while curr >= temp[0]:
			now = -1
			ind = -1
			for k in range(5):
				if temp[k] <= curr and temp[k] >= now:
					now = temp[k]
					ind = k
			ans[ind] += curr // now
			curr = curr % now
	print(*ans)
	print(curr)


f = lambda : map(int, input().split())
n = input()
seq = f()
(a, b, c, d, e) = f()
counts = [0, 0, 0, 0, 0]
score = 0
for p in seq:
	score += p
	if score >= e:
		counts[4] += score // e
		score = score % e
	if score >= d:
		counts[3] += score // d
		score = score % d
	if score >= c:
		counts[2] += score // c
		score = score % c
	if score >= b:
		counts[1] += score // b
		score = score % b
	if score >= a:
		counts[0] += score // a
		score = score % a
print(' '.join(list(map(str, counts))))
print(str(score))


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
n = ii()
b = li()
prices = li()
t = 0
ans = [0] * 5
for i in range(n):
	t += b[i]
	for j in range(5):
		c = t // prices[-j - 1]
		ans[-j - 1] += c
		t -= c * prices[-j - 1]
print(wr(ans))
print(t)


n = int(input())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
i = c = 0
a = [0] * 5
while i < n:
	c += l[i]
	for j in range(4, -1, -1):
		if c >= l1[j]:
			a[j] = a[j] + c // l1[j]
			c %= l1[j]
	i += 1
for i in range(5):
	print(a[i], end=' ')
print()
print(c)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rem = 0
c = [0] * 5
for i in a:
	j = 4
	rem += i
	while j >= 0 and rem >= b[0]:
		x = int(rem / b[j])
		c[j] += x
		rem = rem % b[j]
		j -= 1
for i in range(4):
	print(c[i], end=' ')
print(c[4])
print(rem)


n = int(input())
p = [int(i) for i in input().split()]
cost = [int(i) for i in input().split()]
result = [0 for i in range(5)]
points = 0
for i in p:
	points += i
	for i in range(4, -1, -1):
		result[i] += points // cost[i]
		points = points % cost[i]
for i in result:
	print(i, end=' ')
print(' ')
print(points)


n = int(input())
arr = list(map(int, input().split()))
a = list(map(int, input().split()))
ml = []
j = 1
for i in a:
	ml.append([i, j, 0])
	j += 1
c = 0
ml.sort(reverse=True)
for i in arr:
	c += i
	for t in ml:
		if t[0] <= c:
			t[2] += c // t[0]
			c -= t[0] * (c // t[0])
ml.sort(key=lambda x: x[1])
hmm = []
for i in ml:
	hmm.append(i[2])
print(*hmm)
print(c)


def g(i):
	return i[0]
n = int(input())
lis = list(map(int, input().split()))
(a, b, c, d, e) = list(map(int, input().split()))
items = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
(su, plis) = (0, [(a, 'a'), (b, 'b'), (c, 'c'), (d, 'd'), (e, 'e')])
plis.sort(reverse=True, key=g)
for i in lis:
	su += i
	if su >= min(plis, key=g)[0]:
		j = 0
		while j < 5:
			if plis[j][0] <= su:
				items[plis[j][1]] += su // plis[j][0]
				su = su % plis[j][0]
			j += 1
print(' '.join([str(items[j]) for j in ['a', 'b', 'c', 'd', 'e']]))
print(su)


n = int(input())
p = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
(k_a, k_b, k_c, k_d, k_e) = (0, 0, 0, 0, 0)
res = [a, b, c, d, e]
ans = [0] * 5
res.sort()
s = 0
for i in p:
	s += i
	for j in range(4, -1, -1):
		ans[j] += s // res[j]
		s %= res[j]
print(ans[res.index(a)], ans[res.index(b)], ans[res.index(c)], ans[res.index(d)], ans[res.index(e)])
print(s)


n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
r = [0] * 5
s = 0
for v in a:
	s += v
	for i in range(4, -1, -1):
		if b[i] <= s:
			k = s // b[i]
			s -= k * b[i]
			r[i] += k
print(*r)
print(s)


N = int(input())
Buy = [int(x) for x in input().split()]
Points = [int(x) for x in input().split()]
X = [0] * 5
a = 0
for i in Buy:
	a += i
	for j in range(4, -1, -1):
		div = int(a // Points[j])
		X[j] += div
		a -= div * Points[j]
print(*X)
print(a)


n = int(input())
points = list(map(int, input().split()))
curr_points = 0
prizes = list(map(int, input().split()))
result = [0] * 5
for i in range(n):
	curr_points += points[i]
	for x in range(4, -1, -1):
		result[x] += curr_points // prizes[x]
		curr_points = curr_points % prizes[x]
print(*result, sep=' ')
print(curr_points)


n = int(input())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
points = 0
ans = [0, 0, 0, 0, 0]
for x in range(n):
	points += p[x]
	for y in range(4, -1, -1):
		ans[y] += points // c[y]
		points = points % c[y]
for x in ans:
	print(x, end=' ')
print()
print(points)


n = int(input())
l = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
ans = [0] * 5
bal = 0
for i in range(n):
	bal += l[i]
	for j in range(5):
		temp = bal // k[4 - j]
		bal = bal - temp * k[4 - j]
		ans[4 - j] += temp
print(*ans)
print(bal)


import sys
inp = sys.stdin.readlines()
ii = 0
out = []
numwraps = int(inp[ii])
ii += 1
wrappers = [int(w) for w in inp[ii].split()]
ii += 1
prices = [int(p) for p in inp[ii].split()]
ii += 1
items = {}
items[0] = 0
items[1] = 0
items[2] = 0
items[3] = 0
items[4] = 0
monies = 0
for check in range(numwraps):
	monies += wrappers[check]
	items[4] += monies // prices[4]
	monies = monies % prices[4]
	items[3] += monies // prices[3]
	monies = monies % prices[3]
	items[2] += monies // prices[2]
	monies = monies % prices[2]
	items[1] += monies // prices[1]
	monies = monies % prices[1]
	items[0] += monies // prices[0]
	monies = monies % prices[0]
res = ''
for numbought in list(items.values()):
	res += str(numbought)
	res += ' '
print(res)
print(monies)


n = int(input())
p = input().split(' ')
pr = input().split(' ')
sum = 0
ans = list()
for i in range(5):
	ans.append(0)
for i in range(n):
	sum += int(p[i])
	for j in range(5):
		ans[5 - j - 1] += sum // int(pr[5 - j - 1])
		sum = sum % int(pr[5 - j - 1])
for i in range(5):
	print(ans[i], end=' ')
print(sum)


import sys
import math
n = int(sys.stdin.readline())
pn = [int(x) for x in sys.stdin.readline().split()]
(a, b, c, d, e) = [int(x) for x in sys.stdin.readline().split()]
rez = [0] * 5
r = 0
for i in range(n):
	r += pn[i]
	while r >= a:
		if r >= e:
			rez[4] += int(r / e)
			r = r % e
		elif r >= d:
			rez[3] += int(r / d)
			r = r % d
		elif r >= c:
			rez[2] += int(r / c)
			r = r % c
		elif r >= b:
			rez[1] += int(r / b)
			r = r % b
		elif r >= a:
			rez[0] += int(r / a)
			r = r % a
print(' '.join([str(x) for x in rez]))
print(r)


def readln(inp=None):
	return tuple(map(int, (inp or input()).split()))
(n,) = readln()
p = readln()
abcde = readln()
ans = [0] * 5
cur = 0
for c in p:
	cur += c
	for i in range(4, -1, -1):
		ans[i] += cur // abcde[i]
		cur %= abcde[i]
print(*ans)
print(cur)


n = int(input())
p = [int(i) for i in input().split()]
di = [int(i) for i in input().split()]
res = [0] * 5
them = 0
for i in range(n):
	p[i] += them
	for j in range(4, -1, -1):
		res[j] = res[j] + p[i] // di[j]
		p[i] %= di[j]
	them = p[i]
print(*res, sep=' ')
print(them)


n = int(input())
p = list(map(int, input().split()))
s = [0] * 5
e = sorted([(j, i) for (i, j) in enumerate(map(int, input().split()))])[::-1]
c = 0
for x in p:
	c += x
	while c >= min(e)[0]:
		for y in e:
			s[y[1]] += c // y[0]
			c %= y[0]
print(' '.join(map(str, s)), c, sep='\n')


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
points = 0
b = list(map(int, input().split()))
final = [0, 0, 0, 0, 0]
for itr in range(n):
	points += a[itr]
	while points >= b[0]:
		k = bisect_right(b, points) - 1
		final[k] += points // b[k]
		points %= b[k]
print(*final)
print(points)


r = lambda : map(int, input().split())
n = int(input())
po = list(r())
pr = list(r())
re = [0] * 5
s = 0
for i in po:
	s += i
	for j in range(4, -1, -1):
		if s >= pr[j]:
			re[j] += s // pr[j]
			s = s % pr[j]
print(' '.join(map(str, re)))
print(s)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(input())
	p = lis()
	prizes = lis()[::-1]
	curr = 0
	ans = [0] * 5
	for i in range(n):
		curr += p[i]
		for j in range(5):
			ans[j] += curr // prizes[j]
			curr = curr % prizes[j]
	print(*ans[::-1])
	print(curr)
testcase(1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(*ele, end='\n')
n = L()[0]
P = L()
A = L()
cost = 0
F = [0] * 5
for i in range(n):
	cost += P[i]
	for j in range(4, -1, -1):
		x = cost // A[j]
		F[j] += x
		cost -= A[j] * x
print(*F)
print(cost)
endtime = time.time()


import bisect
n = int(input())
a = list(map(int, input().split()))
c = list(map(int, input().split()))
ch = [0 for i in range(5)]
l = 0
for i in range(len(a)):
	l += a[i]
	while True:
		p = bisect.bisect_right(c, l)
		if p == 0:
			break
		ch[p - 1] += l // c[p - 1]
		l = l % c[p - 1]
	else:
		l += a[i]
print(*ch)
print(l)


n = int(input())
p = [int(x) for x in input().split()]
(a, b, c, d, e) = map(int, input().split())
su = 0
ans = [0 for i in range(5)]
for i in p:
	su += i
	while su >= a:
		if su >= e:
			ans[4] += su // e
			su -= su // e * e
		elif su >= d:
			ans[3] += su // d
			su -= su // d * d
		elif su >= c:
			ans[2] += su // c
			su -= su // c * c
		elif su >= b:
			ans[1] += su // b
			su -= su // b * b
		elif su >= a:
			ans[0] += su // a
			su -= su // a * a
print(*ans)
print(su)


import sys
import os
from math import sqrt, gcd, ceil, log, floor, sin, pi
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline

def read():
	return list(map(int, input().strip().split()))

def read_f():
	return list(map(float, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	ans_ = []
	n = int(input())
	arr = read()
	priceList = read()
	points = 0
	ans = [0] * 5
	for i in range(n):
		points += arr[i]
		while points >= priceList[0]:
			ind = bisect(priceList, points) - 1
			ans[ind] += points // priceList[ind]
			points %= priceList[ind]
	print(*ans)
	print(points)
main()


n = int(input())
points = input().split()
prizes = input().split()
prizes.reverse()
prizes2 = [0, 0, 0, 0, 0]
p = 0
for i in points:
	p += int(i)
	for j in range(5):
		prizes2[j] += p // int(prizes[j])
		p %= int(prizes[j])
prizes2.reverse()
for o in range(len(prizes2)):
	print(prizes2[o], end=' ')
print('\n%d' % p)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	t = list(map(int, input().split()))
	hand = 0
	ind = [0] * 6
	for i in range(n):
		i1 = 0
		hand += l[i]
		no = 1
		while i1 != -1:
			i1 = -1
			for j in range(5):
				if t[j] <= hand:
					p = t[j]
					i1 = j
			if i1 != -1:
				ind[i1] += hand // p
				hand -= hand // p * p
	print(*ind[:-1])
	print(hand)


n = int(input())
p = map(int, input().split())
pr = [[x, 0] for x in map(int, input().split())]
c = 0
for pi in p:
	c += pi
	for pri in reversed(pr):
		k = c // pri[0]
		c -= k * pri[0]
		pri[1] += k
print(' '.join(map(str, (pri[1] for pri in pr))))
print(c)


I = lambda : list(map(int, input().split()))
I()
P = I()
A = I()
C = [0] * 5
s = 0
for p in P:
	s += p
	while True:
		i = -1
		while i < 4 and A[i + 1] <= s:
			i += 1
		if i < 0:
			break
		x = s // A[i]
		C[i] += x
		s -= x * A[i]
print(*C)
print(s)


I = lambda : list(map(int, input().split()))
I()
p = I()
c = I()
t = [0] * 5
v = 0
for x in p:
	v += x
	for i in range(4, -1, -1):
		t[i] += v // c[i]
		v %= c[i]
P = print
P(' '.join(map(str, t)))
P(v)


n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
d = dict()
c = 0
for x in range(5):
	d.update({a[x]: 0})
for x in range(n):
	c += p[x]
	for y in sorted(d.keys(), reverse=True):
		if c // y > 0:
			d[y] += c // y
			c %= y
f = [d[x] for x in sorted(d.keys())]
print(*f)
print(c)


def main():
	from sys import stdin, stdout
	import bisect
	n = int(stdin.readline())
	p = tuple(map(int, stdin.readline().split()))
	P = tuple(map(int, stdin.readline().split()))
	record = [0 for x in range(5)]
	points = 0
	for i in p:
		points += i
		while points >= P[0]:
			index = bisect.bisect_right(P, points)
			if index:
				index -= 1
				number = points // P[index]
				record[index] += number
				points -= P[index] * number
	for i in record:
		stdout.write(str(i) + ' ')
	stdout.write('\n' + str(points))
main()


n = int(input())
points = [int(x) for x in input().split()]
gifts = [int(x) for x in input().split()]
gift_freq = [0 for _ in range(len(gifts))]
points_left = 0
for i in points:
	points_left += i
	for g in range(len(gifts) - 1, -1, -1):
		can_buy = points_left // gifts[g]
		points_left -= gifts[g] * can_buy
		gift_freq[g] += can_buy
for i in gift_freq:
	print(i, end=' ')
print('\n' + str(points_left))


n = int(input())
l = list(map(int, input().split()))
cost = list(map(int, input().split()))
ans = [0] * 5
points = 0
for i in range(n):
	points += l[i]
	while points >= cost[0]:
		for j in range(1, 6):
			if points >= cost[-j]:
				amt = points // cost[-j]
				points %= cost[-j]
				ans[-j] += amt
print(*ans)
print(points)


import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))
pr = list(map(int, input().split()))
x = []
for i in range(5):
	x.append([pr[i], i])
pr.sort()
x.sort()
s = 0
ans = [0] * 5
for i in range(n):
	s = s + p[i]
	for j in range(4, -1, -1):
		if s >= pr[j]:
			f = s // pr[j]
			s = s - f * pr[j]
			ans[x[j][1]] += f
print(*ans)
print(s)


num = int(input())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
prizes = [0, 0, 0, 0, 0]
d.reverse()
k = 0
for i in c:
	k += i
	for j in range(5):
		if k >= d[j]:
			cc = int(k / d[j])
			k -= cc * d[j]
			prizes[j] += cc
prizes.reverse()
print(*prizes)
print(k)


n = int(input())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [0 for i in range(5)]
ct = 0
for i in l:
	ct += i
	for j in range(4, -1, -1):
		if ct >= a[j]:
			ans[j] += ct // a[j]
			ct %= a[j]
print(*ans)
print(ct)


n = int(input())
points = [int(i) for i in input().strip().split(' ')]
prize = [int(i) for i in input().strip().split(' ')]
p = 0
nop = [0] * 5
for point in points:
	p += point
	i = 4
	while i > -1 and p >= prize[0]:
		z = int(p / prize[i])
		p = p % prize[i]
		nop[i] += z
		i -= 1
print(*nop)
print(p)


n = int(input())
arr = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
ans = [0, 0, 0, 0, 0]
p = 0
for x in arr:
	p += x
	while p >= a:
		if p >= a:
			if p >= b:
				if p >= c:
					if p >= d:
						if p >= e:
							k = p // e
							p -= k * e
							ans[4] += k
						else:
							k = p // d
							p -= k * d
							ans[3] += k
					else:
						k = p // c
						p -= k * c
						ans[2] += k
				else:
					k = p // b
					p -= k * b
					ans[1] += k
			else:
				k = p // a
				p -= k * a
				ans[0] += k
print(' '.join((str(elem) for elem in ans)))
print(p)


n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))[::-1]
s = [0] * 5
c = 0
for i in range(n):
	c += l[i]
	for j in range(5):
		s[j] += c // d[j]
		c = c % d[j]
print(*s[::-1])
print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
import bisect as bi
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
a = Ri()
p = Ri()
ans = [0] * 5
left = 0
for i in range(n):
	a[i] += left
	while True:
		ind = bi.bisect_right(p, a[i])
		ind -= 1
		if ind < 0:
			break
		ans[ind] += a[i] // p[ind]
		a[i] = a[i] % p[ind]
	left = a[i]
print(*ans)
print(left)


n = int(input())
p = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
r = [0] * 6
s = 0
for i in p:
	s = s + i
	if s >= e:
		r[5] += s // e
		s = s % e
	if s >= d:
		r[4] += s // d
		s = s % d
	if s >= c:
		r[3] += s // c
		s = s % c
	if s >= b:
		r[2] += s // b
		s = s % b
	if s >= a:
		r[1] += s // a
		s = s % a
for i in r[1:]:
	print(i, end=' ')
print()
print(s)


n = int(input())
arr = list(map(int, input().split()))
prizes = list(map(int, input().split()))
ans = []
curr = 0
map = {}
for i in range(5):
	map[i] = 0
for i in range(n):
	curr += arr[i]
	if curr >= prizes[0]:
		for j in range(4, -1, -1):
			if prizes[j] <= curr:
				map[j] += curr // prizes[j]
				curr = curr % prizes[j]
for i in map:
	print(map[i], end=' ')
print()
print(curr)


cin = input
n = int(cin())
a = [int(v) for v in cin().split()]
b = [int(v) for v in cin().split()]
(c, r) = ([0] * 5, 0)
for i in a:
	r += i
	for j in range(4, -1, -1):
		c[j] += r // b[j]
		r %= b[j]
print('%s\n%d' % (' '.join((str(i) for i in c)), r))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
e = list(map(int, input().split()))
c = sorted(((i, int(val)) for (i, val) in enumerate(input().split())))
ans = [0] * 5
a = 0
for i in range(n):
	a += e[i]
	for i in range(4, -1, -1):
		if a >= c[i][1]:
			var = a // c[i][1]
			a -= c[i][1] * var
			ans[c[i][0]] += var
print(*ans)
print(a)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
from bisect import *
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = rr()
brr = rr()
x = min(brr)
s = 0
ans = [0] * 5
for i in arr:
	s += i
	while s >= x:
		pos = bisect(brr, s) - 1
		ans[pos] += s // brr[pos]
		s = s % brr[pos]
print(*ans)
print(s)


n = int(input())
p = [0] * (n + 1)
p = list(map(int, input().split()))
(a, b, c, d, e) = map(int, input().split())
points = int(0)
cnt = [0] * 5
for i in range(0, n):
	points = points + p[i]
	while 1:
		if points >= e:
			val = points / e
			val = int(val)
			points -= e * val
			cnt[4] += val
		elif points >= d:
			val = points / d
			val = int(val)
			points -= d * val
			cnt[3] += val
		elif points >= c:
			val = points / c
			val = int(val)
			points -= c * val
			cnt[2] += val
		elif points >= b:
			val = points / b
			val = int(val)
			points -= b * val
			cnt[1] += val
		elif points >= a:
			val = points / a
			val = int(val)
			points -= a * val
			cnt[0] += val
		else:
			break
ans = ' '.join(map(str, cnt))
print(ans)
print(points)