#TP0000069. Khám sức khỏe cho bò (Bảng Đồng) (Cow Checkups (Bronze))
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 cows standing in a line at positions through . Cow at position has species . The veterinarian examines the cow at position if and only if its species equals .
John performs exactly one operation: choose integers and reverse the order of all cows between positions and , inclusive. Two operations are considered different whenever their pairs differ, even if the resulting lineups happen to be identical.
For each integer from through , count the number of operations producing exactly 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 .
The second line contains integers .
The third line contains integers .
Output
Print exactly lines. Line () contains the number of interval reversals that result in exactly examined cows.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
3
1 3 2
3 2 1
Output
3
3
0
0
Explanation
There are possible intervals. Reversing any singleton , , or leaves the lineup , with no matches against . Reversing , , and yields , , and , each with exactly one match. Thus the frequencies for are .