PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000021. So sánh số lần xuất hiện trước và sau (Pashmak and Parmida's problem)
HỌC THEO LỘ TRÌNH
3 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
So sánh số lần xuất hiện trước và sau (Pashmak and Parmida's problem)
Pashmak and Parmida's problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
For every position , let be the number of occurrences of in the prefix from through . For every , let be the number of occurrences of in the suffix from through . Count pairs such that . These are occurrence counts, not comparisons of and .
Input
The first line contains . The second line contains positive integers .
Output
Print one 64-bit integer: the number of index pairs satisfying the frequency inequality.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
7
1 2 1 1 2 2 1
Output
8
Explanation
Compute prefix occurrence counts and suffix occurrence counts at every position, then count only index pairs with . The supplied sample yields such pairs.