#U2425JB3. Cow Checkups

Cow Checkups

**Note: We suggest using a language other than Python to earn full credit on this problem.**

Farmer John's NN (1N75001≤N≤7500) cows are standing in a line, with cow 11 at the front of the line and cow NN at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from 11 to NN. The ii'th cow from the front of the line is of species aiai (1aiN1≤ai≤N).

FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the ii'th cow in the line, only if it is of species bibi (1biN1≤bi≤N).

FJ is lazy and does not want to completely reorder his cows. He will perform the following operation ​exactly once​.

  • Select two integers ll and rr such that 1lrN1≤l≤r≤N. Reverse the order of the cows that are between the ll-th cow and the rr-th cow in the line, inclusive.

FJ wants to measure how effective this approach is. For each c=0Nc=0…N, help FJ find the number of distinct operations (l,rl,r) that result in exactly cc cows being checked. Two operations (l1**,r1l1,r1) and (l2,r2l2,r2) are different if l1l2l1≠l2 or r1r2**r1≠r2.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains an integer NN.The second line contains a1**,a2**,,aNa1,a2,…,aN.

The third line contains b1**,b2**,,bNb1,b2,…,bN.

OUTPUT FORMAT (print output to the terminal / stdout):

Output N+1N+1 lines with the ii-th line containing the number of distinct operations (l,rl,r) that result in i1i−1 cows being checked.

SAMPLE INPUT:

3
1 3 2
3 2 1

SAMPLE OUTPUT:

3
3
0
0

If FJ chooses (l=1,r=1l=1,r=1), (l=2,r=2l=2,r=2), or (l=3,r=3l=3,r=3) then no cows will be checked. Note that those operations do not modify any of the cows' locations.The following operations result in one cow being checked.

  • l=1,r=2l=1,r=2: FJ reverses the order of the first and second cows so the species of each cow in the new lineup will be [3,1,2][3,1,2]. The first cow will be checked.
  • l=2,r=3l=2,r=3: FJ reverses the order of the second and third cows so the species of each cow in the new lineup will be [1,2,3][1,2,3]. The second cow will be checked.
  • l=1,r=3l=1,r=3: FJ reverses the order of the first, second, and third cows so the species of each cow in the new lineup will be [2,3,1][2,3,1]. The third cow will be checked.

SAMPLE INPUT:

3
1 2 3
1 2 3

SAMPLE OUTPUT:

0
3
0
3

The three possible operations that cause 33 cows to be checked are (l=1,r=1l=1,r=1), (l=2,r=2l=2,r=2), and (l=3,r=3l=3,r=3).#### SAMPLE INPUT:

7
1 3 2 2 1 3 2
3 2 2 1 2 3 1

SAMPLE OUTPUT:

0
6
14
6
2
0
0
0

The two possible operations that cause 44 cows to be checked are (l=4,r=5l=4,r=5) and (l=5,r=7l=5,r=7).#### SCORING:

  • Inputs 4-6: N100N≤100
  • Inputs 7-13: No additional constraints

Problem credits: Chongtian Ma and Haokai Ma