PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000132. Thử trà (Tea Tasting)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Thử trà (Tea Tasting)

Tea Tasting

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn tea varieties and nn tasters, both numbered from 11 to nn. Variety ii initially has aia_i milliliters. Taster jj can drink up to bjb_j milliliters per step. Initially taster ii drinks from variety ii. After each step every active taster moves to the previous variety; anyone past variety 1 leaves. Each drink is the minimum of the remaining quantity and that taster's capacity. Compute the total amount drunk by each taster over all steps.

Input

The first line contains nn. The second line has a1,…,ana_1,\ldots,a_n; the third has b1,…,bnb_1,\ldots,b_n.

Output

Print nn integers in taster order, giving the total milliliters consumed by each taster.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai,bi≤1091\le a_i,b_i\le10^9, 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ai,bi≤1091\le a_i,b_i\le10^9, 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤ai,bi≤1091\le a_i,b_i\le10^9, 1≤i≤n1\le i\le n.

Examples

Input

3
10 20 15
9 8 6

Output

9 9 12

Explanation

Step 1: tasters drink 9,8,69,8,6, leaving tea quantities (1,12,9)(1,12,9). Step 2: taster 1 has left, taster 2 drinks 11 from variety 1, and taster 3 drinks 66 from variety 2; totals are now (9,9,12)(9,9,12) and tea is (0,6,9)(0,6,9). Step 3: taster 3 reaches empty variety 1, drinking nothing. Print 9 9 12.