#P6854. Tram
Tram
Description
You are about to debut.
Your coach and classmates have contacted a photographer for you, and you come to take promotional photos by Des Voeux Road.
There are buildings on the street, arranged in a line from left to right, numbered from to . The height of building is .
A photo can be described by an ordered pair , where . This photo contains all buildings with indices in .
The photographer thinks a photo is beautiful if and only if it satisfies both conditions below:
- For any , if buildings of heights and both appear in the photo, then buildings of height also appear in the photo.
- For any , buildings of height either do not appear in the photo, or appear exactly times in the photo.
The photographer asks you: how many different beautiful photos can be taken in total?
Two photos and are different if and only if or .
Input Format
The first line contains a positive integer , representing the number of buildings.
The next line contains positive integers. The -th integer is the height of building .
Output Format
Output one line containing one integer, representing the number of different beautiful photos that can be taken.
10
2 2 1 1 2 2 3 1 3 3
8
Hint
This problem uses bundled tests. You can get the score for a subtask only if you pass all test points in that subtask.
- Subtask 1 (10 points): .
- Subtask 2 (5 points): .
- Subtask 3 (10 points): .
- Subtask 4 (20 points): .
- Subtask 5 (30 points): .
- Subtask 6 (25 points): .
For all testdata: .
Note that the answer may exceed the range of a -bit signed integer.
The input size is large, so please use a fast input method.
Translated by ChatGPT 5
京公网安备 11011102002149号