There are $N$ buckets numbered $1$ through $N$. The buckets contain balls; each ball has a color between $1$ and $K$. Let's denote the number of balls with color $j$ that are initially in bucket $i$ by $a_{i, j}$.
For each $i$ from $1$ to $N-1$ (in this order), someone draws a ball uniformly at random from bucket $i$ and puts it into bucket $i+1$, then continues to draw the next ball. After putting a ball in bucket $N$, this person draws a ball, again uniformly at random, from bucket $N$.
For each color from $1$ to $K$, find the probability that the ball drawn from bucket $N$ has this color.

-----Input-----
- The first line of the input contains two space-separated integers $N$ and $K$. 
- $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains $K$ space-separated integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, K}$.

-----Output-----
Print a single line containing $K$ space-separated real numbers. For each valid $i$, the $i$-th of these numbers should denote the probability that the last drawn ball has color $i$. your answer will be considered correct if absolute or relative error does not exceed $10^{-6}$

-----Constraints-----
- $1 \le N, K \le 1,000$
- $0 \le a_{i, j} \le 10$ for each valid $i, j$
- initially, there is at least one ball in bucket $1$

-----Subtasks-----
Subtask #1 (30 points): $1 \le N, K \le 100$
Subtask #2 (70 points): original constraints

-----Example Input-----
2 2
0 1
1 1

-----Example Output-----
0.333333 0.666667

-----Explanation-----

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Mathematics

Probability


Solutions:
a = input()
(n, k) = a.split()
n = int(n)
k = int(k)
A = []
sum = []
for i in range(n):
	A.append(list(map(int, input().split())))
for i in range(n):
	sum.append(0)
	for j in range(k):
		sum[i] = sum[i] + A[i][j]
for j in range(k):
	p1 = A[0][j] / sum[0]
	for i in range(1, n):
		p1 = (A[i][j] + 1) * p1 / (sum[i] + 1) + A[i][j] * (1 - p1) / (sum[i] + 1)
	print('%.6f' % p1, end=' ')


t = 1
for test in range(t):
	(n, k) = map(int, input().split())
	D = {}
	S = {}
	for i in range(1, n + 1):
		D[i] = list(map(int, input().split()))
		S[i] = sum(D[i])
	dp = [[0 for i in range(k)] for j in range(n + 1)]
	for j in range(k):
		dp[1][j] = D[1][j] / S[1]
	for i in range(2, n + 1):
		for j in range(k):
			dp[i][j] = dp[i - 1][j] * (D[i][j] + 1) / (S[i] + 1) + (1 - dp[i - 1][j]) * D[i][j] / (S[i] + 1)
	print(*dp[n])


(n, k) = tuple(map(int, input().split()))
(lines, balls) = ([], [])
for i in range(n):
	lines.append(list(map(int, input().split())))
	balls.append(sum(lines[i]))
probability = [[0 for i in range(k)] for j in range(n)]
for i in range(k):
	probability[0][i] = lines[0][i] / balls[0]
for i in range(1, n):
	for j in range(k):
		probability[i][j] = probability[i - 1][j] * ((lines[i][j] + 1) / (balls[i] + 1))
		probability[i][j] += (1 - probability[i - 1][j]) * (lines[i][j] / (balls[i] + 1))
for i in range(k):
	print(probability[n - 1][i], end=' ')


__author__ = 'Ronald Kaiser'
__email__ = 'raios dot catodicos at gmail dot com'
(N, K) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
p = list([v / s for v in a])
for _ in range(N - 1):
	a = list(map(int, input().split()))
	sa = sum(a) + 1
	p = [(p[i] + a[i]) / sa for i in range(K)]
print(*p)


import sys
line = input().split()
n = int(line[0])
k = int(line[1])
a = [[int(x) for x in input().split()] for y in range(n)]
p = [[0 for x in range(k)] for y in range(n)]
s = [sum(x) for x in a]
pSum = 0
for j in range(k):
	p[0][j] = float(a[0][j] / s[0])
	pSum += p[0][j]
for i in range(1, n):
	for j in range(k):
		p[i][j] = (pSum - p[i - 1][j]) * (a[i][j] / (s[i] + 1)) + p[i - 1][j] * (a[i][j] + 1) / (s[i] + 1)
for x in p[n - 1]:
	sys.stdout.write(str(x) + ' ')
sys.stdout.write('\n')


l = []
prob = []
(n, k) = [int(x) for x in input().split()]
for i in range(n):
	kk = list(map(int, input().split()))
	l.append(kk)
	prob.append([0 for _ in kk])
for i in range(n - 1):
	for j in range(k):
		temp = l[i][j] / sum(l[i])
		prob[i][j] = temp
		l[i + 1][j] += prob[i][j]
temp = sum(l[n - 1])
for i in range(k):
	print(l[n - 1][i] / temp, end=' ')


R = lambda : map(int, input().split())
(n, k) = R()
a = [list(R()) for _ in range(n)]
p = [0.0] * k
d = 0
for r in a:
	s = sum(r) + d
	d = 1
	p = [(x + y) / s for (x, y) in zip(r, p)]
print(*p)


(N, K) = map(int, input().split(' '))
ball = []
for i in range(N):
	ball.append(list(map(int, input().split(' '))))
prob = [[0 for i in range(K)] for j in range(N)]
for i in range(N):
	temp = 0
	for j in range(K):
		temp += ball[i][j]
	ball[i].append(temp)
for i in range(K):
	prob[0][i] = ball[0][i] / ball[0][K]
for i in range(1, N):
	c = ball[i][K]
	for j in range(0, K):
		b = ball[i][j]
		prob[i][j] = (b + prob[i - 1][j]) / (c + 1)
for i in range(K):
	print('%.6f' % prob[N - 1][i], end=' ')


(n, k) = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(1, n):
	for j in range(k):
		a[i][j] = a[i][j] + a[i - 1][j] / sum(a[i - 1])
for x in range(k):
	print(a[n - 1][x] / sum(a[n - 1]), end=' ')


(n, k) = list(map(int, input().split()))
a = [[] for i in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
f = []
p = []
for i in range(n):
	s1 = 0
	for j in range(k):
		s1 += a[i][j]
	f.append(s1)
for i in range(k):
	s = []
	l = a[0][i] / f[0]
	s.append(l)
	for j in range(1, n):
		s.append((l + a[j][i]) / (f[j] + 1))
		l = s[j]
	p.append(s[n - 1])
r = str(p[0]) + ' '
for i in range(1, k):
	r += str(p[i]) + ' '
print(r)


def calcProb(color, n, a, sums):
	prob = a[0][color] / sums[0]
	for i in range(n - 1):
		prob = (a[i + 1][color] + 1) / (sums[i + 1] + 1) * prob + a[i + 1][color] / (sums[i + 1] + 1) * (1 - prob)
	return prob
(n, k) = map(int, input().split())
a = []
sums = []
for i in range(n):
	a.append(list(map(int, input().split())))
	sums.append(sum(a[i]))
for i in range(k):
	print(calcProb(i, n, a, sums), end=' ')


(n, k) = map(int, input().split())
arr = [0 for j in range(n)]
arrsum = []
for i in range(n):
	m = [int(j) for j in input().split()]
	arrsum = arrsum + [sum(m)]
	arr[i] = m
	prev = 1
for i in range(k):
	for j in range(n):
		if j == 0:
			pickb = arr[j][i] / arrsum[0]
			prev = pickb
		else:
			pickb = (arr[j][i] + 1) / (arrsum[j] + 1) * prev + (1 - prev) * arr[j][i] / (arrsum[j] + 1)
			prev = pickb
	print(pickb, end=' ')


(N, K) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
sizes = [sum(bucket) for bucket in a]
res = []
for j in range(K):
	p = a[0][j]
	for i in range(1, N):
		p = (a[i][j] + p) / (sizes[i] + 1)
	res.append(p)
print(' '.join((str(x) for x in res)))


(n, k) = map(int, input().split())
bucket = list(map(int, input().split()))
pb = sum(bucket)
prop = [i / pb if pb > 0 else 0 for i in bucket]
for i in range(1, n):
	bucket = list(map(int, input().split()))
	nb = sum(bucket) + 1
	current = [0 for _ in range(k)]
	for j in range(k):
		current[j] = (bucket[j] + 1) / nb * prop[j] + bucket[j] / nb * (1 - prop[j])
	prop = current[:]
print(('{:.6f} ' * n).format(*prop))


import sys
import math

def main(arr):
	k = len(arr[0])
	n = len(arr)
	dp = [[0] * k for i in range(n + 1)]
	summation_arr = []
	for i in range(len(arr)):
		a = 1 if i != 0 else 0
		summation_arr.append(sum(arr[i]) + a)
	for i in range(1, len(dp)):
		for j in range(len(dp[0])):
			dp[i][j] = (dp[i - 1][j] + arr[i - 1][j]) / summation_arr[i - 1]
	ans = []
	for i in range(k):
		ans.append(dp[-1][i])
	print(*ans)
(n, k) = input().split()
n = int(n)
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
main(arr)


(N, K) = map(int, input().split())
A = [[0 for j in range(K)] for i in range(N)]
for i in range(N):
	A[i] = list(map(int, input().split()))
B = []
P = []
for i in range(N):
	B.append(sum(A[i]))
for j in range(K):
	p = float(0)
	for i in range(N):
		if i != 0:
			p = p * ((A[i][j] + 1) / (B[i] + 1)) + (1 - p) * (A[i][j] / (B[i] + 1))
		else:
			p = A[i][j] / B[i]
	P.append(p)
for i in P:
	print(i, end=' ')


(n, k) = map(int, input().split())
a = [[*map(int, input().split())] for _ in range(n)]
ps = [sum(ai) for ai in a]
res = [0] * k
pps_ = 0
for i in range(n):
	ps_ = ps[i]
	if pps_ > 0:
		ps_ += 1
	for j in range(k):
		try:
			res[j] = (res[j] + a[i][j]) / ps_
		except:
			res[j] = 0
	pps_ = ps_
print(' '.join(map(lambda x: str(round(x, 10)), res)))


(n, k) = map(int, input().split())
arr = []
for i in range(n):
	kl = list(map(int, input().split()))
	arr.append(kl)
pre = []
for i in range(1005):
	pre.append([])
for i in range(1005):
	for j in range(1005):
		pre[i].append(0)
s = [0] * 1005
for i in range(0, k):
	pre[0][i] = arr[0][i]
	s[0] += pre[0][i]
for i in range(1, n):
	for j in range(k):
		pre[i][j] = arr[i][j] + pre[i - 1][j] / s[i - 1]
		s[i] += pre[i][j]
for i in range(k):
	print('%0.6f' % (pre[n - 1][i] / s[n - 1]), end=' ')
print()


(n, k) = map(int, input().strip().split())
a = []
c = []
for i in range(0, n):
	b = list(map(int, input().strip().split()))
	a.append(b)
	c.append(sum(b))
p = []
init = []
for i in range(0, k):
	val = a[0][i] / c[0]
	init.append(val)
p.append(init)
for i in range(1, n):
	init = []
	for j in range(0, k):
		val = p[i - 1][j] * ((a[i][j] + 1) / (c[i] + 1)) + (1 - p[i - 1][j]) * (a[i][j] / (c[i] + 1))
		init.append(val)
	p.append(init)
for i in range(0, k):
	print(p[n - 1][i], end=' ')


(n, k) = map(int, input().split())
li = list()
nn = n
for i in range(n):
	li.append([])
	li[i] = input().split()
	for j in range(k):
		li[i][j] = int(li[i][j])
sum1 = sum(li[0])
li2 = list()
li3 = list()
li4 = list()
for i in li:
	li4.append(sum(i))
for i in range(k):
	li2.append(li[0][i] / sum1)
for c in range(k):
	j = li2[c]
	for i in range(1, n):
		sum2 = li4[i]
		col = li[i][c]
		p1 = col / (sum2 + 1) * (1 - j)
		p2 = (col + 1) / (sum2 + 1) * j
		pt = p1 + p2
		j = pt
	li3.append(j)
for i in li3:
	print(i, end=' ')


(n, k) = map(int, input().split())
prob = [0 for i in range(k)]
for i in range(n):
	vals = list(map(int, input().split()))
	sumval = sum(vals)
	if i == 0:
		for j in range(k):
			prob[j] = vals[j] / sumval
	else:
		for j in range(k):
			prob[j] = (vals[j] + prob[j]) / (sumval + 1)
for i in range(0, len(prob) - 1):
	print(round(prob[i], 6), end=' ')
print(round(prob[-1], 6), end='')


(n, k) = list(map(int, input().split()))
bk = [0] * n
sm = [0] * n
for i in range(0, n):
	bk[i] = list(map(int, input().split(' ')))
	sm[i] = sum(bk[i])
dp = [[0] * n for i in range(0, k)]
for i in range(0, k):
	dp[i][0] = bk[0][i] / sm[0]
for i in range(0, k):
	for e in range(1, n):
		dp[i][e] = (bk[e][i] + dp[i][e - 1]) / (sm[e] + 1)
for i in range(0, k):
	print(dp[i][n - 1], end=' ')


def pblt(i, buck, arrnt):
	buc = buck[0]
	p = buc[i] / arrnt[0]
	for j in range(1, len(buck)):
		buc = buck[j]
		nt = arrnt[j]
		nf = buc[i]
		p = p * ((nf + 1) / (nt + 1)) + (1 - p) * (nf / (nt + 1))
	return p
(n, k) = map(int, input().split())
buck = []
arrnt = []
for i in range(n):
	l = list(map(int, input().split()))
	buck.append(l)
for i in buck:
	arrnt.append(sum(i))
for i in range(k):
	print(pblt(i, buck, arrnt), end=' ')


(n, k) = map(int, input().split())
game = []
for i in range(n):
	game.append(list(map(int, input().split())))
summ = 0
for i in range(n - 1):
	for j in range(k):
		summ += game[i][j]
	for j in range(k):
		game[i + 1][j] += game[i][j] / summ
	summ = 0
deno = sum(game[i + 1])
for i in game[i + 1]:
	print(str.format('{0:.6f}', i / deno), end=' ')


(n, k) = map(int, input().split())
ans = [x[:] for x in [[0] * k] * n]
row = list(map(int, input().split()))
s = sum(row)
for i in range(k):
	ans[0][i] = row[i] / s
for i in range(1, n):
	inp = list(map(int, input().split()))
	s = sum(inp) + 1
	for j in range(k):
		tmp1 = (inp[j] + 1) / s
		tmp2 = inp[j] / s
		ans[i][j] = tmp1 * ans[i - 1][j] + (1 - ans[i - 1][j]) * tmp2
print(' '.join([str(i) for i in ans[n - 1]]))


(n, k) = map(int, input().split())
prob = [0 for i in range(k)]
for i in range(n):
	vals = list(map(int, input().split()))
	s = sum(vals)
	if i == 0:
		for j in range(k):
			prob[j] = vals[j] / s
	else:
		for j in range(k):
			prob[j] = (vals[j] + prob[j]) / (s + 1)
prob = [round(prob[i], 6) for i in range(k)]
print(*prob)


(n, k) = map(int, input().split())
dp = [[0] * k for i in range(n)]
sumr = [0] * n
for i in range(n):
	dp[i] = [int(x) for x in input().split()]
for i in range(n):
	sumr[i] = sum(dp[i])
for i in range(k):
	for j in range(n):
		if j == 0:
			prev = dp[0][i] / sumr[0]
		else:
			curr = prev * (dp[j][i] + 1) / (sumr[j] + 1) + (1 - prev) * dp[j][i] / (sumr[j] + 1)
			prev = curr
	print(prev, end=' ')


(n, k) = map(int, input().split())
dp = [[0] * k for x in range(n)]
ct = [0] * n
for i in range(n):
	dp[i] = list(map(int, input().split()))
	ct[i] = sum(dp[i])
for i in range(k):
	pb = 0.0
	for j in range(n):
		if j == 0:
			pv = dp[0][i] / ct[0]
		else:
			tmp = pv * (dp[j][i] + 1) / (ct[j] + 1) + (1 - pv) * dp[j][i] / (ct[j] + 1)
			pv = tmp
	print(pv, end=' ')


from collections import defaultdict
(n, k) = map(int, input().split())
record = {}
record = defaultdict(lambda : 1, record)
for i in range(n):
	inlist = list(map(int, input().split()))
	total = sum(inlist)
	for j in range(k):
		if i != 0:
			record[str(j)] = record[str(j)] * (inlist[j] + 1) / (total + 1) + (1 - record[str(j)]) * inlist[j] / (total + 1)
		elif i == 0:
			record[str(j)] *= inlist[j] / total
for i in range(k):
	print(round(record[str(i)], 6), end=' ')


(n, k) = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for _ in range(n)]
total = [sum(e) for e in a]
for i in range(k):
	p = a[0][i] / total[0]
	for j in range(1, n):
		p = (a[j][i] + p) / (total[j] + 1)
	print(p, end=' ')


__author__ = 'Ronald Kaiser'
__email__ = 'raios dot catodicos at gmail dot com'

def solve(px, y, K):
	s = []
	sy = sum(y)
	for i in range(K):
		s.append(px[i] * ((y[i] + 1) / (sy + 1)) + (1 - px[i]) * (y[i] / (sy + 1)))
	return s
(N, K) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
p = list([v / s for v in a])
for _ in range(N - 1):
	a = list(map(int, input().split()))
	p = solve(p, a, K)
print(*p)


(n, k) = input().split()
(n, k) = (int(n), int(k))
prob = [0] * k
for i in range(n):
	ls = [int(x) for x in input().split(' ')]
	prob = [ls[i] + prob[i] for i in range(k)]
	s = sum(prob)
	prob = [i / s for i in prob]
for i in prob:
	print(i, end=' ')
print('')


import numpy as np
(n, k) = [int(s) for s in input().split()]
arr = np.zeros((n, k), dtype=int)
for i in range(n):
	arr[i, :] = np.array(list(map(int, input().split())))
finalProb = arr[0, :] / np.sum(arr[0, :])
for i in range(1, n):
	finalProb = (finalProb + arr[i, :]) / (np.sum(arr[i, :]) + 1)
print(' '.join(map(str, list(finalProb))))


(n, k) = list(map(int, input().split()))
prob_if_adding = [0 for _ in range(k)]
for i in range(n):
	bucket = list(map(int, input().split()))
	s = sum(bucket)
	if i == 0:
		for j in range(k):
			prob_if_adding[j] = bucket[j] / s
	else:
		for j in range(k):
			prob_if_adding[j] = prob_if_adding[j] * ((bucket[j] + 1) / (s + 1)) + (1 - prob_if_adding[j]) * (bucket[j] / (s + 1))
for j in range(k):
	print(round(prob_if_adding[j], 6), end=' ')


(n, k) = map(int, input().split())
ans = [0] * k
a = list(map(int, input().split()))
r = sum(a)
for i in range(k):
	ans[i] = a[i] / r
for i in range(n - 1):
	a = list(map(int, input().split()))
	r = sum(a) + 1
	for j in range(k):
		ans[j] = (a[j] + 1) / r * ans[j] + a[j] / r * (1 - ans[j])
print(*ans)


(n, k) = input().split()
(n, k) = (int(n), int(k))
test = n
slist = []
sumlist = []
while test:
	test -= 1
	sum = 0
	x = [float(a) for a in input().strip().split(' ')]
	slist.append(x)
	for a in x:
		sum += a
	sumlist.append(sum)
for c in range(0, k):
	prob = 0
	base = 1
	for i in range(0, n):
		if i == n - 1:
			base *= sumlist[n - i - 1]
		else:
			base *= sumlist[n - i - 1] + 1
		prob += slist[n - i - 1][c] / base
	print(prob, end=' ')


s = list(map(int, input().split()))
(n, k) = (s[0], s[1])
l = []
for i in range(0, n):
	s = list(map(int, input().split()))
	l.append(s)
p = []
total = sum(l[0])
for i in range(k):
	p.append(l[0][i] / total)
for i in range(1, n):
	total = sum(l[i])
	for j in range(0, k):
		x = p[j] * (l[i][j] + 1) / (total + 1)
		y = (1 - p[j]) * l[i][j] / (total + 1)
		p[j] = x + y
for i in range(k):
	print(p[i], end=' ')


def main():
	(n, k) = tuple(map(int, input().split()))
	a = [list(map(int, input().split())) for _ in range(n)]
	p = [a[0][i] / sum(a[0]) for i in range(k)]
	for i in range(1, n):
		s = sum(a[i]) + 1
		p = [(p[j] * (a[i][j] + 1) + (1 - p[j]) * a[i][j]) / s for j in range(k)]
	for i in range(k):
		print(round(p[i], 6), end=' ')
main()


(n, k) = map(int, input().split())
pro = [0] * k
no_k = [0] * k
no_of_balls = 0
for i in range(n):
	arr = [int(x) for x in input().split()]
	no_of_balls += sum(arr)
	for j in range(k):
		pro[j] = (pro[j] + arr[j]) / no_of_balls
	no_of_balls = 1
print(*pro, sep=' ')


import sys

def main():
	(n, k) = [int(item) for item in input().split()]
	a = [[0] * k for i in range(n)]
	for i in range(n):
		a[i] = [int(item) for item in input().split()]
	t = [sum(a[i]) for i in range(n)]
	p = [[0] * k for i in range(n)]
	for j in range(k):
		p[0][j] = a[0][j] / t[0]
	for i in range(1, n):
		for j in range(k):
			p1 = p[i - 1][j] * ((a[i][j] + 1) / (t[i] + 1))
			p2 = (1 - p[i - 1][j]) * (a[i][j] / (t[i] + 1))
			p[i][j] = p1 + p2
	print(*p[n - 1])
	return 0
main()


(n, k) = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
ans = [[0 for i in range(k)] for j in range(n)]
sumi = []
for i in range(n):
	p = 0
	for j in range(k):
		p += a[i][j]
	sumi.append(p)
for j in range(k):
	for i in range(n):
		if i == 0:
			ans[i][j] = a[i][j] / sumi[0]
		else:
			ans[i][j] = ans[i - 1][j] * (a[i][j] + 1) / (sumi[i] + 1) + (1 - ans[i - 1][j]) * a[i][j] / (sumi[i] + 1)
	x = ans[n - 1][j] * pow(10, 6)
	if x % 10 >= 5:
		x = int(x)
		x += 1
	else:
		x = int(x)
	print(x / 1000000, end=' ')


(n, k) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
x = []
s = sum(l[0])
for i in l[0]:
	x.append(i / s)
s = []
for i in l:
	s.append(sum(i))
for i in range(1, n):
	y = []
	for j in range(k):
		a = 0
		a = l[i][j] / (s[i] + 1) * (sum(x) - x[j])
		a += x[j] * ((l[i][j] + 1) / (s[i] + 1))
		y.append(a)
	x = y[:]
for i in x:
	print(round(i, 6), end=' ')


(n, k) = list(map(int, input().strip().split()))
a = []
for i in range(n):
	al = list(map(int, input().strip().split()))
	a.append(al)
op = []
s = []
for j in range(n):
	s.append(sum(a[j]))
for i in range(k):
	x = a[0][i] / sum(a[0])
	for j in range(n):
		x = (x + a[j][i]) / (1 + s[j])
	op.append(x)
print(' '.join(list(map(str, op))))


R = lambda : map(int, input().split())
(n, k) = R()
a = [list(R()) for _ in range(n)]
s = sum(a[0])
p = [x / s for x in a[0]]
for r in a[1:]:
	s = sum(r) + 1
	for i in range(k):
		p[i] = (r[i] + p[i]) / s
print(*p)


(n, k) = list(map(int, input().split()))
ps = []
ip = []
for i in range(n):
	t = list(map(int, input().split()))
	ip.append(t)
for i in range(n):
	l = []
	for j in range(k):
		l.append(0)
	ps.append(l)
for i in range(n):
	sum1 = sum(ip[i])
	for j in range(k):
		if i == 0:
			ps[i][j] = ip[i][j] / sum1
		else:
			ps[i][j] = ps[i - 1][j] * (ip[i][j] + 1) / (sum1 + 1) + (1 - ps[i - 1][j]) * ip[i][j] / (sum1 + 1)
for t in range(k):
	print(ps[n - 1][t], end=' ')


def propability(arr):
	new_arr = []
	sum_arr = sum(arr)
	for i in arr:
		new_arr.append(i / sum_arr)
	return new_arr

def pro_arr(arr, n, k):
	for i in range(n - 1):
		temp_arr = propability(arr[i])
		for j in range(k):
			arr[i + 1][j] += temp_arr[j]
	print(*propability(arr[-1]))
(n, k) = [int(i) for i in input().split()]
arr = [[int(i) for i in input().split()] for i in range(n)]
pro_arr(arr, n, k)


(N, K) = map(int, input().split())
buckets = []
for i in range(N):
	buckets.append(list(map(int, input().split())))
for b in range(len(buckets) - 1):
	s = sum(buckets[b])
	for i in range(K):
		buckets[b + 1][i] += buckets[b][i] / s
s = sum(buckets[-1])
for i in range(K):
	print(buckets[-1][i] / s, end=' ')
print()


(n, k) = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
ans = a[n - 1]
b = [sum(a[i]) for i in range(n)]
suf = []
cur = 1
for i in range(n - 2, -1, -1):
	if i != 0:
		cur *= b[i] + 1
	else:
		cur *= b[i]
	suf.append(cur)
suf = suf[::-1]
for i in range(n - 1):
	for j in range(k):
		ans[j] += a[i][j] / suf[i]
for i in range(n):
	print(ans[i] / sum(ans), end=' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
b = [0.0 for i in range(n)]
for j in range(n):
	b[j] = a[j] / s
for i in range(1, n):
	a = list(map(int, input().split()))
	s = sum(a)
	for j in range(n):
		b[j] = (1.0 - b[j]) * a[j] / (s + 1) + b[j] * (a[j] + 1) / (s + 1)
for i in range(n):
	print(b[i], end=' ')


def modifyarr(n, k, l, sumi):
	dp = [[0 for i in range(k)] for i in range(n)]
	for j in range(k):
		dp[0][j] = l[0][j] / sumi[0]
	for i in range(1, n):
		for j in range(k):
			dp[i][j] = dp[i - 1][j] * (l[i][j] + 1) / (sumi[i] + 1) + (1 - dp[i - 1][j]) * (l[i][j] / (sumi[i] + 1))
	for i in range(k):
		print(dp[n - 1][i], end=' ')
	print()
l = input().split()
n = int(l[0])
k = int(l[1])
l = []
sumi = [0 for i in range(n)]
for i in range(n):
	lo = input().split()
	li = [int(i) for i in lo]
	l.append(li)
	sumi[i] = sum(li)
modifyarr(n, k, l, sumi)


(n, k) = map(int, input().split())
sum = [0] * n
l = [[0 for i in range(k)] for j in range(n)]
for i in range(n):
	l[i] = list(map(int, input().split()))
for i in range(n):
	for j in range(k):
		sum[i] += l[i][j]
for i in range(k):
	x = l[0][i]
	carry = x / sum[0]
	for j in range(1, n):
		y = l[j][i]
		z = sum[j]
		carry = carry * ((y + 1) / (z + 1)) + (1 - carry) * (y / (z + 1))
	print(round(carry, 6), end=' ')


R = lambda : map(int, input().split())
(n, k) = R()
L = []
for i in range(n):
	L.append(list(R()))
P = [0] * k
S = []
for i in range(n):
	S.append(sum(L[i]))
for i in range(n):
	for j in range(k):
		if i == 0:
			if L[i][j] != 0:
				P[j] = L[i][j] / S[i]
		elif P[j] == 0:
			if L[i][j] != 0:
				P[j] = L[i][j] / (S[i] + 1)
		else:
			P[j] = P[j] * ((L[i][j] + 1) / (S[i] + 1)) + (1 - P[j]) * (L[i][j] / (S[i] + 1))
print(*P)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

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

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s

def calc(n, m, r):
	s = 0
	for i in range(0, r + 1, 2):
		s += ncr1(n, i) * ncr1(m, i)
		s %= mod
	return s
for _ in range(1):
	(n, k) = map(int, input().split())
	ans = [0] * (k + 1)
	a = list(map(int, input().split()))
	r = sum(a)
	for i in range(1, k + 1):
		ans[i] = a[i - 1] / r
	for i in range(n - 1):
		a = list(map(int, input().split()))
		r = sum(a) + 1
		for j in range(1, k + 1):
			ans[j] = (a[j - 1] + 1) / r * ans[j] + a[j - 1] / r * (1 - ans[j])
	print(*ans[1:])


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	(n, k) = map(int, sys.stdin.readline().split(' '))
	a = []
	for i in range(n):
		p = list(map(int, sys.stdin.readline().split(' ')))
		a.append(p)
	for i in range(1, n):
		tot = sum(a[i - 1])
		for j in range(k):
			a[i][j] += a[i - 1][j] / tot
	tot = sum(a[n - 1])
	ans = []
	for j in range(k):
		ans.append(a[n - 1][j] / tot)
	print(*ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


(n, k) = map(int, input().split())
ar = []
total = [0] * n
for i in range(n):
	ar.append(list(map(int, input().split())))
	total[i] = sum(ar[-1])
for i in range(k):
	ans = 0
	for j in range(n):
		if j == 0:
			ans = ar[j][i] / total[j]
		else:
			ans = ans * (1 / (total[j] + 1)) + ar[j][i] / (total[j] + 1)
	print(ans, end=' ')


import numpy as np
(n, k) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
bucket = np.zeros([k], dtype=float)
deno = sum(matrix[0])
for j in range(k):
	bucket[j] += matrix[0][j] / deno
for i in range(1, n):
	deno = sum(matrix[i]) + 1
	for j in range(k):
		bucket[j] = (bucket[j] * (matrix[i][j] + 1) + (1 - bucket[j]) * matrix[i][j]) / deno
print(' '.join((str(round(x, 6)) for x in bucket)))


(n, k) = list(map(int, input().strip().split()))
a = []
for i in range(n):
	b = list(map(int, input().strip().split()))
	a.append(b)
prob = [a[0][x] / sum(a[0]) for x in range(k)]
for i in range(n - 1):
	sums = sum(a[i + 1]) + 1
	prob = [(prob[x] * (a[i + 1][x] + 1) + (1 - prob[x]) * a[i + 1][x]) / sums for x in range(k)]
for i in range(k):
	print(prob[i], end=' ')


from decimal import Decimal
(n, k) = map(int, input().split())
mat = []
ans = [0] * k
for i in range(n):
	row = list(map(int, input().split()))
	mat.append(row)
dp = [[0] * n for _ in range(k)]
sums = [0] * n
for i in range(n):
	sums[i] = sum(mat[i])
for col in range(n):
	dp[0][col] = mat[0][col] / sums[0]
for row in range(1, n):
	for col in range(k):
		a = dp[row - 1][col] * (mat[row][col] + 1) / (sums[row] + 1)
		b = (1 - dp[row - 1][col]) * mat[row][col] / (sums[row] + 1)
		dp[row][col] = dp[row - 1][col] * (mat[row][col] + 1) / (sums[row] + 1) + (1 - dp[row - 1][col]) * mat[row][col] / (sums[row] + 1)
		dp[row][col] = round(dp[row][col], 6)
print(' '.join(map(str, dp[n - 1])))


l = []
prob = []
(n, k) = map(int, input().split(' '))
for i in range(n):
	lt = list(map(int, input().split(' ')))
	l.append(lt)
	prob.append([0 for _ in lt])
for i in range(n - 1):
	for j in range(k):
		prob[i][j] = l[i][j] / sum(l[i])
		l[i + 1][j] += prob[i][j]
res = []
for j in range(k):
	prob[n - 1][j] = l[n - 1][j] / sum(l[n - 1])
	res.append(prob[n - 1][j])
for j in range(k):
	print('{}'.format(res[j]), end=' ')
print('\t')


import sys
sys.setrecursionlimit(10 ** 6)

def p(K, N, A, total, dp):
	if N == 0:
		return A[N][K] / total[N]
	elif (K, N) in dp:
		return dp[K, N]
	else:
		x = p(K, N - 1, A, total, dp)
		dp[K, N] = (A[N][K] + x) / (total[N] + 1)
		return dp[K, N]
(N, K) = [int(i) for i in input().split()]
A = []
total = []
for i in range(N):
	x = [int(i) for i in input().split()]
	total.append(sum(x))
	A.append(x)
s = ''
dp = {}
for i in range(K):
	s += str(p(i, N - 1, A, total, dp)) + ' '
print(s.strip())


(n, k) = map(int, input().split())
balls = []
buck_sum = []
for i in range(n):
	balls.append(list(map(int, input().split())))
	buck_sum.append(sum(balls[-1]))
p = []
for i in range(k):
	p.append(balls[0][i] / buck_sum[0])
for i in range(1, n):
	for j in range(k):
		p[j] = p[j] * (balls[i][j] + 1) / (buck_sum[i] + 1) + (1 - p[j]) * balls[i][j] / (buck_sum[i] + 1)
print(*p)


nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]
l = []
sum = []
for i in range(n):
	l.append(list(map(int, input().split(' '))))
	sum.append(0)
	for j in range(k):
		sum[i] = sum[i] + l[i][j]
for i in range(k):
	p1 = l[0][i] / sum[0]
	for j in range(n - 1):
		p1 = p1 * ((l[j + 1][i] + 1) / (sum[j + 1] + 1)) + (1 - p1) * (l[j + 1][i] / (sum[j + 1] + 1))
	print(p1, end='')
	print(' ', end=' ')