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

#SP0000238. Người sống sót cuối cùng (Last Man Standing)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Người sống sót cuối cùng (Last Man Standing)

Last Man Standing

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn heroes. Hero ii starts with health hih_i and armor aia_i (current armor initially equals aia_i). Before each game, choose a fixed positive integer damage value xx. In every round, all living heroes simultaneously take xx damage.

  • If current armor is strictly greater than xx, subtract xx from the armor, leaving health unchanged.
  • Otherwise, subtract 11 from health and reset current armor to the initial value aia_i.

A hero dies when health reaches zero. The game ends when every hero has died. A unique last hero earns the number of rounds during which that hero was the only survivor; all other heroes earn zero. If multiple heroes die in the final round, everyone gets zero.

Play the game separately for every positive integer xx, resetting the heroes each time. Find the maximum score each hero can achieve in any game.

Input

  • The first line contains integer nn, the number of heroes.
  • The second line contains exactly nn integers h1,h2,…,hnh_1,h_2,\ldots,h_n.
  • The third line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print nn integers in one line; the ii-th is hero ii's maximum score over all positive damage values xx.

Subtasks

  • Subtask 1 (20 points): 1≤n≤61\le n\le6; 1≤hi≤201\le h_i\le20, 1≤ai≤201\le a_i\le20 for all 1≤i≤n1\le i\le n.

  • Subtask 2 (30 points): 1≤n≤40001\le n\le4000; 1≤hi≤40001\le h_i\le4000, 1≤ai≤40001\le a_i\le4000 for all 1≤i≤n1\le i\le n.

  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤hi≤2⋅1051\le h_i\le2\cdot10^5, 1≤ai≤2⋅1051\le a_i\le2\cdot10^5 for all 1≤i≤n1\le i\le n.

Examples

Input

3
3 1 2
3 11 5

Output

1 1 1

Explanation

The (h,a)(h,a) pairs are (3,3)(3,3), (1,11)(1,11), and (2,5)(2,5). For fixed xx, hero ii loses one health every ⌈ai/x⌉\lceil a_i/x\rceil rounds and dies at time Ti(x)=hi⌈ai/x⌉T_i(x)=h_i\lceil a_i/x\rceil.

At x=1x=1, death times are (9,11,10)(9,11,10), so hero 2 gets 11−10=111-10=1. At x=4x=4 they are (3,3,4)(3,3,4), so hero 3 gets 11. At x=6x=6 they are (3,2,2)(3,2,2), so hero 1 gets 11. For the remaining damage values, x=2x=2 gives (6,6,6)(6,6,6), x=3x=3 gives (3,4,4)(3,4,4), and x=5x=5 gives (3,3,2)(3,3,2). Values x=7,8,9,10x=7,8,9,10 all yield (3,2,2)(3,2,2), while every x≥11x\ge11 yields (3,1,2)(3,1,2). No case gives any hero more than one point, and each hero attains exactly one in some game. Hence output 1 1 1.