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

#TP0000069. Khám sức khỏe cho bò (Bảng Đồng) (Cow Checkups (Bronze))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khám sức khỏe cho bò (Bảng Đồng) (Cow Checkups (Bronze))

Cow Checkups (Bronze)

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer John has NN cows standing in a line at positions 11 through NN. Cow at position ii has species aia_i. The veterinarian examines the cow at position ii if and only if its species equals bib_i.

John performs exactly one operation: choose integers 1≤l≤r≤N1\le l\le r\le N and reverse the order of all cows between positions ll and rr, inclusive. Two operations are considered different whenever their pairs (l,r)(l,r) differ, even if the resulting lineups happen to be identical.

For each integer cc from 00 through NN, count the number of operations producing exactly cc examined cows. This is the USACO Bronze version, which asks for a frequency distribution, not the aggregate total requested by the Silver problem of the same name.

Input

The first line contains NN.

The second line contains NN integers a1,…,aNa_1,\ldots,a_N.

The third line contains NN integers b1,…,bNb_1,\ldots,b_N.

Output

Print exactly N+1N+1 lines. Line c+1c+1 (0≤c≤N0\le c\le N) contains the number of interval reversals that result in exactly cc examined cows.

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le 12; 1≤ai,bi≤N1\le a_i,b_i\le N for every 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤4001\le N\le 400; 1≤ai,bi≤N1\le a_i,b_i\le N for every 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤75001\le N\le 7500; 1≤ai,bi≤N1\le a_i,b_i\le N for every 1≤i≤N1\le i\le N.

Examples

Input

3
1 3 2
3 2 1

Output

3
3
0
0

Explanation

There are 3⋅4/2=63\cdot4/2=6 possible intervals. Reversing any singleton [1,1][1,1], [2,2][2,2], or [3,3][3,3] leaves the lineup [1,3,2][1,3,2], with no matches against [3,2,1][3,2,1]. Reversing [1,2][1,2], [2,3][2,3], and [1,3][1,3] yields [3,1,2][3,1,2], [1,2,3][1,2,3], and [2,3,1][2,3,1], each with exactly one match. Thus the frequencies for c=0,1,2,3c=0,1,2,3 are 3,3,0,03,3,0,0.