← Back to Problems
Settlement Chain
Medium standard Linear Algebra
Time limit: 2 s per test  ·  Memory: 256 MB

A settlement system moves money through n accounts, numbered 1 to n, in strict order: account i can only credit accounts j > i.

You are given the n x n integer matrix N, where N[j][i] is the multiplier applied to account i's start-of-tick balance and credited to account j during a tick (N[j][i] = 0 whenever j <= i). At each tick, every account's new balance is its old balance plus all credits received during the tick. You are also given the starting balances v_1, ..., v_n.

The system runs for k ticks. Output the exact final balance of every account.

Input

The first line contains n and k. The next n lines contain the matrix N, row j on line j. The last line contains v_1, ..., v_n.

Output

n integers: the final balances, in order.

Constraints

1 <= n <= 100

0 <= k <= 10^18

|N[j][i]| <= 10, |v_i| <= 10^6, all integers

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Examples

input
3 2
0 0 0
1 0 0
0 1 0
1 0 0
output
1 2 1
input
3 1000000000000000000
0 0 0
1 0 0
0 1 0
1 0 0
output
1 1000000000000000000 499999999999999999500000000000000000
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2